-
Notifications
You must be signed in to change notification settings - Fork 122
/
kubectl_interactive.go
45 lines (33 loc) · 1.03 KB
/
kubectl_interactive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package peirates
import (
"fmt"
"strings"
)
func kubectl_interactive(connectionString ServerInfo) error {
println(`
This function allows you to run a kubectl command, with only a few restrictions.
Your command must not:
- specify a different service account
- use a different API server
- run for longer than a few seconds (as in kubectl exec)
Your command will crash this program if it is not permitted.
These requirements are dynamic - watch new versions for changes.
Leave off the "kubectl" part of the command. For example:
- get pods
- get pod podname -o yaml
- get secret secretname -o yaml
`)
fmt.Printf("Please enter a kubectl command: ")
input, err := ReadLineStripWhitespace()
arguments := strings.Fields(input)
kubectlOutput, _, err := runKubectlSimple(connectionString, arguments...)
if err != nil {
println("[-] Could not perform action: kubectl ", input)
return err
}
kubectlOutputLines := strings.Split(string(kubectlOutput), "\n")
for _, line := range kubectlOutputLines {
println(line)
}
return nil
}