-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (56 loc) · 1.72 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
package main
import (
"fmt"
"github.com/wongearl/karmadactl-util/pkg/common"
"github.com/wongearl/karmadactl-util/pkg/join"
"github.com/wongearl/karmadactl-util/pkg/k8sclient"
"github.com/wongearl/karmadactl-util/pkg/unjoin"
"k8s.io/client-go/kubernetes"
)
func main() {
client, err := k8sclient.NewKubernetesClient("/home/king/.kube/config", "", 30, 5)
if err != nil {
fmt.Println("NewKubernetesClient err:", err)
return
}
testJoin(client)
testUnJoin(client)
}
func testJoin(k8sClient kubernetes.Interface) {
j := &join.Join{
KarmdactlArg: common.KarmdactlArg{
ClusterName: "member1",
ClusterConfigSecretName: "member-config",
ClusterConfigSecretNamespace: "default",
ClusterContext: "[email protected]",
KarmadaConfigSecretName: "karmada-kubeconfig",
KarmadaConfigSecretNamespace: "karmada-system",
KarmadaContext: "karmada-apiserver",
},
}
stdout, stderr, err := j.JoinCluster(k8sClient)
if err != nil {
fmt.Println("err:", err, "stderr:", stderr)
return
}
fmt.Println("stdout:", stdout)
}
func testUnJoin(k8sClient kubernetes.Interface) {
u := &unjoin.Unjoin{
KarmdactlArg: common.KarmdactlArg{
ClusterName: "member1",
ClusterConfigSecretName: "member-config",
ClusterConfigSecretNamespace: "default",
ClusterContext: "[email protected]",
KarmadaConfigSecretName: "karmada-kubeconfig",
KarmadaConfigSecretNamespace: "karmada-system",
KarmadaContext: "karmada-apiserver",
},
}
stdout, stderr, err := u.UnJoinCluster(k8sClient)
if err != nil {
fmt.Println("err:", err, "stderr:", stderr)
return
}
fmt.Println("stdout:", stdout)
}