-
Notifications
You must be signed in to change notification settings - Fork 20
/
kube_list.go
53 lines (42 loc) · 1.04 KB
/
kube_list.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
package cmd
import (
"os"
"github.com/exoscale/cli/table"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// kubeListCmd represents the kube list command
var kubeListCmd = &cobra.Command{
Use: "list",
Short: "List running Kubernetes cluster instances",
Aliases: gListAlias,
RunE: func(cmd *cobra.Command, args []string) error {
return listKubeInstances()
},
}
func listKubeInstances() error {
vms, err := cs.ListWithContext(gContext, &egoscale.VirtualMachine{
Tags: []egoscale.ResourceTag{{
Key: "managedby",
Value: "exokube",
}},
})
if err != nil {
return err
}
table := table.NewTable(os.Stdout)
table.SetHeader([]string{"Name", "IP Address", "Size", "Version", "State"})
for _, key := range vms {
vm := key.(*egoscale.VirtualMachine)
kubeVersion := getKubeInstanceVersion(vm)
if kubeVersion == "" {
continue
}
table.Append([]string{vm.Name, vm.IP().String(), vm.ServiceOfferingName, kubeVersion, vm.State})
}
table.Render()
return nil
}
func init() {
kubeCmd.AddCommand(kubeListCmd)
}