Skip to content

Add message for users to redownload their kubeconfig #274

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions cmd/apikey/apikey_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime"
"strings"
"syscall"
"time"

"github.com/civo/civogo"
"github.com/civo/cli/common"
Expand Down Expand Up @@ -132,6 +133,27 @@ var apikeySaveCmd = &cobra.Command{
config.SaveConfig()
}

if config.Current.Clusters == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should be in the config.go file while CLI is reading/loading the config

client, err := civogo.NewClientWithURL(apiKey, config.Current.Meta.URL, config.Current.Meta.DefaultRegion)
if err != nil {
utility.Error("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)
}
config.Current.Clusters = make(map[string]bool)
for _, cluster := range clusters.Items {
config.Current.Clusters[cluster.ID] = true
if time.Since(cluster.BuiltAt) > (365 * 24 * time.Hour) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a time.Year, if not you can use time.Day *365 but more importantly, we have to check if it's divisible by the year in which cluster was built.

config.Current.Clusters[cluster.ID] = false
}
}
}
config.SaveConfig()

ow := utility.NewOutputWriterWithMap(map[string]string{"name": name, "key": apiKey})

switch common.OutputFormat {
Expand Down
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.")
},
}
5 changes: 3 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