This repository has been archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
etcd.go
59 lines (53 loc) · 1.54 KB
/
etcd.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
package cmd
import (
"github.com/flanksource/karina/pkg/provision"
"github.com/spf13/cobra"
)
var Etcd = &cobra.Command{
Use: "etcd",
}
var etcdHost string
func init() {
Etcd.PersistentFlags().StringVar(&etcdHost, "etcd-host", "", "Etcd hostname to connect through")
Etcd.AddCommand(&cobra.Command{
Use: "status",
Run: func(cmd *cobra.Command, args []string) {
platform := getPlatform(cmd)
client, err := platform.GetClientset()
if err != nil {
platform.Fatalf("could not get client: %v", err)
}
if err := provision.GetEtcdClient(platform, client, etcdHost).PrintStatus(); err != nil {
platform.Fatalf("Failed to get etcd status: %v", err)
}
},
})
Etcd.AddCommand(&cobra.Command{
Use: "remove-member [name]",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
platform := getPlatform(cmd)
client, err := platform.GetClientset()
if err != nil {
platform.Fatalf("could not get client: %v", err)
}
if err := provision.GetEtcdClient(platform, client, etcdHost).RemoveMember(args[0]); err != nil {
platform.Fatalf(err.Error())
}
},
})
Etcd.AddCommand(&cobra.Command{
Use: "move-leader [name]",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
platform := getPlatform(cmd)
client, err := platform.GetClientset()
if err != nil {
platform.Fatalf("could not get client: %v", err)
}
if err := provision.GetEtcdClient(platform, client, etcdHost).MoveLeader(args[0]); err != nil {
platform.Fatalf(err.Error())
}
},
})
}