Skip to content

Commit

Permalink
add update-kubeconfig cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Jan 24, 2025
1 parent 1ab807f commit a7bc304
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func init() {
KubernetesCmd.AddCommand(kubernetesUpgradeCmd)
KubernetesCmd.AddCommand(kubernetesRemoveCmd)
KubernetesCmd.AddCommand(kubernetesRecycleCmd)
KubernetesCmd.AddCommand(kubernetesUpdateKubeconfigCmd)

home, err := os.UserHomeDir()
if err != nil {
Expand Down
44 changes: 44 additions & 0 deletions cmd/kubernetes/kubernetes_update_kubeconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package kubernetes

import (
"fmt"
"os"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
"github.com/spf13/cobra"
)

var kubernetesUpdateKubeconfigCmd = &cobra.Command{
Use: "update-kubeconfig",
Short: "Update kubeconfig for the specified cluster",
Example: "civo kubernetes update-kubeconfig CLUSTER_NAME",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
utility.EnsureCurrentRegion()

client, err := config.CivoAPIClient()
if common.RegionSet != "" {
client.Region = common.RegionSet
}
if err != nil {
utility.Error("Creating the connection to Civo's API failed with %s", err)
os.Exit(1)
}

cluster, err := client.FindKubernetesCluster(args[0])
if err != nil {
utility.Error("Finding cluster failed with %s", err)
os.Exit(1)
}

err = utility.ObtainKubeConfig(localPathConfig, cluster.KubeConfig, true, true, cluster.Name)
if err != nil {
utility.Error("Updating kubeconfig failed with %s", err)
os.Exit(1)
}

fmt.Printf("Updated kubeconfig with cluster %s configuration\n", utility.Green(cluster.Name))
},
}

0 comments on commit a7bc304

Please sign in to comment.