-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (73 loc) · 1.83 KB
/
main.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
82
package main
import (
"context"
"fmt"
"log"
"path/filepath"
"strings"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"kmodules.xyz/client-go/tools/exec"
)
func main() {
masterURL := ""
kubeconfigPath := filepath.Join(homedir.HomeDir(), ".kube", "config")
config, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigPath)
if err != nil {
log.Fatalf("Could not get Kubernetes config: %s", err)
}
dc2 := dynamic.NewForConfigOrDie(config)
gvrNode := schema.GroupVersionResource{
Group: "",
Version: "v1",
Resource: "nodes",
}
nodes, err := dc2.Resource(gvrNode).List(context.TODO(), metav1.ListOptions{})
if err != nil {
panic(err)
}
for _, obj := range nodes.Items {
fmt.Printf("%+v\n", obj.GetName())
}
nodes, err = dc2.Resource(gvrNode).List(context.TODO(), metav1.ListOptions{})
if err != nil {
panic(err)
}
for _, obj := range nodes.Items {
fmt.Printf("%+v\n", obj.GetName())
}
pod := types.NamespacedName{
Namespace: "demo",
Name: "voyager-test-ingress-754d884cf-dmwrd",
}
out, err := exec.Exec(config, pod, exec.Container("haproxy"), exec.Command("ps"))
if err != nil {
panic(err)
}
fmt.Println(out)
out22, err := exec.Exec(
config,
pod,
exec.Container("haproxy"),
exec.Command("cat", "/shared/haproxy.pid"))
if err != nil {
panic(err)
}
fmt.Println(out22)
out2, err := exec.Exec(config, pod, exec.Container("haproxy"), exec.Command("/bin/kill", "-SIGHUP", strings.TrimSpace(out22)))
if err != nil {
panic(err)
}
fmt.Println(out2)
time.Sleep(2 * time.Second)
out3, err := exec.Exec(config, pod, exec.Container("haproxy"), exec.Command("ps"))
if err != nil {
panic(err)
}
fmt.Println(out3)
}