-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
78 lines (69 loc) · 1.88 KB
/
main.go
File metadata and controls
78 lines (69 loc) · 1.88 KB
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
package main
import (
"bufio"
"fmt"
"log"
"os"
"k8s.io/client-go/kubernetes"
)
var kubeClient *kubernetes.Clientset
var workloads []Workload
func main() {
var err error
kubeClient, err = loadKubeClient()
if err != nil {
log.Fatalf("Failed to create kubernetes client, err: %v", err)
}
if err := printWorkloadsTable(""); err != nil {
log.Fatalf("Failed to print workloads table, err: %v", err)
}
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Println("\nPlease choose a action:")
fmt.Println("1. Show all workloads")
fmt.Println("2. Migrate workload")
fmt.Println("3. Rollback workload")
fmt.Println("4. Patch workload ARM affinity")
fmt.Println("5. Rollback workload ARM affinity")
fmt.Println("6. Exit")
fmt.Print("Input the action number: ")
if !scanner.Scan() {
continue
}
choice := scanner.Text()
switch choice {
case "1":
fmt.Print("Please enter a namespace (leave empty to show all workloads):")
scanner.Scan()
if err := printWorkloadsTable(scanner.Text()); err != nil {
log.Printf("Failed to print workloads table, err: %v\n", err)
}
case "2":
selectedWorkloads, err := selectWorkloads(scanner)
if err != nil {
log.Printf("Failed to select workloads, err: %v\n", err)
}
migrateWorkload(selectedWorkloads)
case "3":
selectedWorkloads, err := selectWorkloads(scanner)
if err != nil {
log.Printf("Failed to select workloads, err: %v\n", err)
}
rollbackWorkload(selectedWorkloads)
case "4":
selectedWorkloads, err := selectWorkloads(scanner)
if err != nil {
log.Printf("Failed to select workloads, err: %v\n", err)
}
patchWorkloadARMAffinity(selectedWorkloads)
case "5":
selectedWorkloads, err := selectWorkloads(scanner)
if err != nil {
log.Printf("Failed to select workloads, err: %v\n", err)
}
rollbackWorkloadARMAffinity(selectedWorkloads)
case "6":
return
}
}
}