-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (54 loc) · 1.23 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
package main
import (
"fmt"
"path"
"time"
"k8s.io/client-go/util/homedir"
)
const (
RESTART_INTERVAL = 10
)
func main() {
kubeconfig := path.Join(homedir.HomeDir(), ".kube/config")
client, err := NewClient(kubeconfig)
if err != nil {
panic(err)
}
dps, err := client.GetDeployments("")
if err != nil {
panic(err)
}
fmt.Println("deployments:")
for _, dp := range dps {
fmt.Println(" - name:", dp.Name)
fmt.Println(" namespace:", dp.Namespace)
fmt.Println(" restarting:", true)
_, err = client.RestartDeployment(&dp)
if err != nil {
fmt.Println(" restarted:", false)
fmt.Println(" error:", err)
continue
}
client.WaitDeployment(&dp)
// time.Sleep(RESTART_INTERVAL * time.Second)
fmt.Println(" restarted:", true)
}
ss, err := client.GetStatefulSet("")
if err != nil {
panic(err)
}
fmt.Println("statefulset:")
for _, s := range ss {
fmt.Println(" - name:", s.Name)
fmt.Println(" namespace:", s.Namespace)
fmt.Println(" restarting:", true)
_, err = client.RestartStatefulSet(&s)
if err != nil {
fmt.Println(" restarted:", false)
fmt.Println(" error:", err)
continue
}
time.Sleep(RESTART_INTERVAL * time.Second)
fmt.Println(" restarted:", true)
}
}