-
Notifications
You must be signed in to change notification settings - Fork 20
/
kube_list.go
70 lines (58 loc) · 1.78 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cmd
import (
"fmt"
"strings"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
type kubeListItemOutput struct {
Name string `json:"name"`
IPAddress string `json:"ipaddress"`
State string `json:"state"`
Size string `json:"size"`
K8sVersion string `json:"k8s_version" outputLabel:"k8s Version"`
DockerVersion string `json:"docker_version"`
CalicoVersion string `json:"calico_version"`
}
type kubeListOutput []kubeListItemOutput
func (o *kubeListOutput) toJSON() { outputJSON(o) }
func (o *kubeListOutput) toText() { outputText(o) }
func (o *kubeListOutput) toTable() { outputTable(o) }
func init() {
kubeCmd.AddCommand(&cobra.Command{
Use: "list",
Short: "List running Kubernetes cluster instances",
Long: fmt.Sprintf(`This command lists existing Kubernetes cluster instances.
Supported output template annotations: %s`,
strings.Join(outputterTemplateAnnotations(&kubeListOutput{}), ", ")),
Aliases: gListAlias,
RunE: func(cmd *cobra.Command, args []string) error {
return output(listKubeInstances())
},
})
}
func listKubeInstances() (outputter, error) {
vms, err := cs.ListWithContext(gContext, &egoscale.VirtualMachine{
Tags: []egoscale.ResourceTag{{
Key: "managedby",
Value: "exokube",
}},
})
if err != nil {
return nil, err
}
out := kubeListOutput{}
for _, key := range vms {
vm := key.(*egoscale.VirtualMachine)
out = append(out, kubeListItemOutput{
Name: vm.Name,
IPAddress: vm.IP().String(),
State: vm.State,
Size: vm.ServiceOfferingName,
K8sVersion: getKubeInstanceVersion(vm, kubeTagKubernetes),
DockerVersion: getKubeInstanceVersion(vm, kubeTagDocker),
CalicoVersion: getKubeInstanceVersion(vm, kubeTagCalico),
})
}
return &out, nil
}