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 support for the VKE HA control plane option #368

Merged
merged 3 commits into from
Oct 31, 2023
Merged
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
33 changes: 20 additions & 13 deletions cmd/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ var (
createLong = `Create kubernetes cluster on your Vultr account`
createExample = `
# Full Example
vultr-cli kubernetes create --label="my-cluster" --region="ewr" --version="v1.20.0+1" \
vultr-cli kubernetes create --label="my-cluster" --region="ewr" --version="v1.28.2+1" \
--node-pools="quantity:3,plan:vc2-1c-2gb,label:my-nodepool,tag:my-tag"

# Shortened with alias commands
vultr-cli k c -l="my-cluster" -r="ewr" -v="v1.20.0+1" -n="quantity:3,plan:vc2-1c-2gb,label:my-nodepool,tag:my-tag"
vultr-cli k c -l="my-cluster" -r="ewr" -v="v1.28.2+1" -n="quantity:3,plan:vc2-1c-2gb,label:my-nodepool,tag:my-tag"
`

getLong = `Get a single kubernetes cluster from your account`
Expand Down Expand Up @@ -241,6 +241,11 @@ func Kubernetes() *cobra.Command { //nolint: funlen
k8Create.Flags().StringP("label", "l", "", "label for your kubernetes cluster")
k8Create.Flags().StringP("region", "r", "", "region you want your kubernetes cluster to be located in")
k8Create.Flags().StringP("version", "v", "", "the kubernetes version you want for your cluster")
k8Create.Flags().Bool(
"high-avail",
false,
"(optional, default false) whether or not the cluster should be deployed with multiple, highly available, control planes",
)
k8Create.Flags().StringArrayP(
"node-pools",
"n",
Expand Down Expand Up @@ -360,6 +365,7 @@ var k8Create = &cobra.Command{
region, _ := cmd.Flags().GetString("region")
nodepools, _ := cmd.Flags().GetStringArray("node-pools")
version, _ := cmd.Flags().GetString("version")
ha, _ := cmd.Flags().GetBool("high-avail")

nps, err := formatNodePools(nodepools)
if err != nil {
Expand All @@ -368,19 +374,20 @@ var k8Create = &cobra.Command{
}

options := &govultr.ClusterReq{
Label: label,
Region: region,
NodePools: nps,
Version: version,
Label: label,
Region: region,
NodePools: nps,
Version: version,
HAControlPlanes: ha,
}

kubernetes, _, err := client.Kubernetes.CreateCluster(context.Background(), options)
vke, _, err := client.Kubernetes.CreateCluster(context.Background(), options)
if err != nil {
fmt.Printf("error creating kubernetes cluster : %v\n", err)
os.Exit(1)
}

printer.Cluster(kubernetes)
printer.Cluster(vke)
},
}

Expand All @@ -394,16 +401,16 @@ var k8List = &cobra.Command{
options := getPaging(cmd)
summarize, _ := cmd.Flags().GetBool("summarize")

k8s, meta, _, err := client.Kubernetes.ListClusters(context.Background(), options)
vkes, meta, _, err := client.Kubernetes.ListClusters(context.Background(), options)
if err != nil {
fmt.Printf("error listing kubernetes clusters : %v\n", err)
os.Exit(1)
}

if summarize {
printer.ClustersSummary(k8s, meta)
printer.ClustersSummary(vkes, meta)
} else {
printer.Clusters(k8s, meta)
printer.Clusters(vkes, meta)
}
},
}
Expand All @@ -422,13 +429,13 @@ var k8Get = &cobra.Command{
},
Run: func(cmd *cobra.Command, args []string) {
id := args[0]
lb, _, err := client.Kubernetes.GetCluster(context.Background(), id)
vke, _, err := client.Kubernetes.GetCluster(context.Background(), id)
if err != nil {
fmt.Printf("error getting cluster : %v\n", err)
os.Exit(1)
}

printer.Cluster(lb)
printer.Cluster(vke)
},
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/printer/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Clusters(cluster []govultr.Cluster, meta *govultr.Meta) {
display(columns{"SERVICE SUBNET", cluster[i].ServiceSubnet})
display(columns{"IP", cluster[i].IP})
display(columns{"ENDPOINT", cluster[i].Endpoint})
display(columns{"HIGH AVAIL", cluster[i].HAControlPlanes})
display(columns{"VERSION", cluster[i].Version})
display(columns{"REGION", cluster[i].Region})
display(columns{"STATUS", cluster[i].Status})
Expand Down Expand Up @@ -70,6 +71,7 @@ func Cluster(k *govultr.Cluster) {
display(columns{"SERVICE SUBNET", k.ServiceSubnet})
display(columns{"IP", k.IP})
display(columns{"ENDPOINT", k.Endpoint})
display(columns{"HIGH AVAIL", k.HAControlPlanes})
display(columns{"VERSION", k.Version})
display(columns{"REGION", k.Region})
display(columns{"STATUS", k.Status})
Expand Down
Loading