Skip to content

Commit

Permalink
Add ability to create node pool with a custom name (#317)
Browse files Browse the repository at this point in the history
* Add ability to create node pool with a custom name

Signed-off-by: Haardik Dharma <haardik@civo.com>

* Length check

---------

Signed-off-by: Haardik Dharma <haardik@civo.com>
Co-authored-by: Haardik Dharma <haardik@civo.com>
  • Loading branch information
haardikdharma10 and haardikdharma10 committed May 8, 2023
1 parent d75d09c commit 50b0606
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func init() {
kubernetesNodePoolCmd.AddCommand(kubernetesNodePoolCreateCmd)
kubernetesNodePoolCreateCmd.Flags().StringVarP(&targetNodesPoolSize, "size", "s", "g4s.kube.medium", "the size of nodes to create.")
kubernetesNodePoolCreateCmd.Flags().IntVarP(&numTargetNodesPool, "nodes", "n", 3, "the number of nodes to create for the pool.")
kubernetesNodePoolCreateCmd.Flags().StringVarP(&nodePoolName, "name", "", "", "the name of the node pool.")

kubernetesNodePoolCmd.AddCommand(kubernetesNodePoolDeleteCmd)
kubernetesNodePoolCmd.AddCommand(kubernetesNodePoolScaleCmd)
Expand Down
15 changes: 13 additions & 2 deletions cmd/kubernetes/kubernetes_nodepool_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/spf13/cobra"
)

var targetNodesPoolSize string
var targetNodesPoolSize, nodePoolName string
var numTargetNodesPool int

var kubernetesNodePoolCreateCmd = &cobra.Command{
Expand Down Expand Up @@ -50,7 +50,18 @@ var kubernetesNodePoolCreateCmd = &cobra.Command{
newPool = append(newPool, civogo.KubernetesClusterPoolConfig{ID: v.ID, Count: v.Count, Size: v.Size})
}

poolID := uuid.NewString()
var poolID string
if nodePoolName != "" {
poolID = nodePoolName
} else {
poolID = uuid.NewString()
}

if len(poolID) > 63 {
utility.Error("The pool name must be less than 64 characters")
os.Exit(1)
}

newPool = append(newPool, civogo.KubernetesClusterPoolConfig{ID: poolID, Count: numTargetNodesPool, Size: targetNodesPoolSize})

configKubernetes := &civogo.KubernetesClusterConfig{
Expand Down

0 comments on commit 50b0606

Please sign in to comment.