Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message for users to redownload their kubeconfig #274

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/kubernetes/kubernetes_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

}
Expand Down
7 changes: 7 additions & 0 deletions cmd/kubernetes/kubernetes_list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kubernetes

import (
"fmt"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
Expand Down Expand Up @@ -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 {
Expand All @@ -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.")
},
}
25 changes: 23 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down