-
Notifications
You must be signed in to change notification settings - Fork 0
/
aerospike.go
81 lines (72 loc) · 2.39 KB
/
aerospike.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"os"
"flag"
"path/filepath"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/util/homedir"
)
func main() {
var kubeconfig *string
var namespaceArg *string
var podNameArg *string
var labelSelectorArg *string
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
namespaceArg = flag.String("namespace", "aerospike", "(optional) namespace")
podNameArg = flag.String("podName", "helloworldpod", "(optional) podName")
labelSelectorArg = flag.String("labelSelector", "k8s-app=kube-dns", "(optional) labelSelector")
flag.Parse()
var namespace string = *namespaceArg
var podName string = *podNameArg
var labelSelector string = *labelSelectorArg
var clientset kubernetes.Interface
for {
fmt.Println(`
0. exit
1. connect to the k8s cluster
2. print out the namespaces on the cluster
3. create a new namespace
4. create a pod in that namespace that runs a simple hello-world container
5. print out pod names and the namespace they are in for any pods that have a label of ‘k8s-app=kube-dns’
6. delete the hello-world pod created from above
7. extra credit - show how an client-go informer works
8. run all`)
fmt.Print("Please enter a number from 0 to 8 : ")
var num int
fmt.Scanf("%d", &num)
switch num {
case 0:
os.Exit(0)
case 1:
clientset = connect(kubeconfig)
case 2:
listNameSpaces(clientset)
case 3:
createNamespace(clientset, namespace)
case 4:
createPod(clientset, namespace, podName)
case 5:
printPodInfo(clientset, labelSelector)
case 6:
deletePod(clientset, namespace, podName)
case 7:
testInformer(clientset, namespace, podName)
case 8:
fmt.Println("Running all 1-7:")
clientset = connect(kubeconfig)
listNameSpaces(clientset)
createNamespace(clientset, namespace)
createPod(clientset, namespace, podName)
printPodInfo(clientset, labelSelector)
testInformer(clientset, namespace, podName)
deletePod(clientset, namespace, podName)
default:
fmt.Println("Please enter a valid action")
}
}
}