diff --git a/cmd/kubernetes/kubernetes_config.go b/cmd/kubernetes/kubernetes_config.go index 2e197990..34a1116b 100644 --- a/cmd/kubernetes/kubernetes_config.go +++ b/cmd/kubernetes/kubernetes_config.go @@ -89,6 +89,7 @@ If you wish to use a custom format, the available fields are: utility.Error("Saving the cluster config failed with %s", err) os.Exit(1) } + config.Current.Clusters[kube.ID] = true } else { fmt.Println("Operation aborted.") os.Exit(1) @@ -100,6 +101,7 @@ If you wish to use a custom format, the available fields are: utility.Error("Saving the cluster config failed with %s", err) os.Exit(1) } + config.Current.Clusters[kube.ID] = true } } diff --git a/cmd/kubernetes/kubernetes_list.go b/cmd/kubernetes/kubernetes_list.go index f3538ef7..1891f237 100644 --- a/cmd/kubernetes/kubernetes_list.go +++ b/cmd/kubernetes/kubernetes_list.go @@ -1,6 +1,8 @@ package kubernetes import ( + "fmt" + "github.com/civo/cli/common" "github.com/civo/cli/config" "github.com/civo/cli/utility" @@ -60,6 +62,9 @@ If you wish to use a custom format, the available fields are: ow.AppendDataWithLabel("status", cluster.Status, "Status") } + if config.Current.Clusters[cluster.ID] == false { + ow.AppendDataWithLabel("name", cluster.Name+" *", "Name") + } } switch common.OutputFormat { @@ -70,5 +75,7 @@ If you wish to use a custom format, the available fields are: default: ow.WriteTable() } + fmt.Println() + utility.Info("Cluster names marked with * are clusters which are over 1 year old. You might want to consider redownloading the config for these clusters. Ignore if already downloaded.") }, } diff --git a/config/config.go b/config/config.go index 463f80bc..d6b95e4b 100644 --- a/config/config.go +++ b/config/config.go @@ -14,8 +14,9 @@ import ( // Config describes the configuration for Civo's CLI type Config struct { - APIKeys map[string]string `json:"apikeys"` - Meta Metadata `json:"meta"` + APIKeys map[string]string `json:"apikeys"` + Meta Metadata `json:"meta"` + Clusters map[string]bool `json:"clusters"` } // Metadata describes the metadata for Civo's CLI @@ -98,6 +99,26 @@ func loadConfig(filename string) { } if time.Since(Current.Meta.LatestReleaseCheck) > (24 * time.Hour) { + if len(Current.APIKeys) > 0 { + client, err := CivoAPIClient() + if err != nil { + fmt.Println("Unable to create a Civo API client, please report this at https://github.com/civo/cli") + os.Exit(1) + } + clusters, err := client.ListKubernetesClusters() + if err != nil { + fmt.Println(err.Error()) + os.Exit(1) + } + Current.Clusters = make(map[string]bool) + for _, cluster := range clusters.Items { + Current.Clusters[cluster.ID] = true + timeSince := int(time.Since(cluster.BuiltAt).Hours()) % 8670 + if timeSince > 0 { + Current.Clusters[cluster.ID] = false + } + } + } Current.Meta.LatestReleaseCheck = time.Now() dataBytes, err := json.Marshal(Current) if err != nil {