Skip to content

Commit

Permalink
Allow scaling from 0 to one or more nodes (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
fulviodenza authored Sep 5, 2024
1 parent 1bdfbc9 commit 3b7f3e2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 34 deletions.
19 changes: 7 additions & 12 deletions cmd/kubernetes/kubernetes_nodepool_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,13 @@ var kubernetesNodePoolCreateCmd = &cobra.Command{
os.Exit(1)
}

poolConfig := civogo.KubernetesClusterPoolUpdateConfig{ID: poolID, Count: numTargetNodesPool, Size: targetNodesPoolSize}
if publicIpNodePool {
if config.Current.RegionToFeatures != nil {
if !config.Current.RegionToFeatures[client.Region].PublicIPNodePools {
utility.Error("The region \"%s\" does not support \"Public IP Node Pools\" feature", client.Region)
os.Exit(1)
}
}
poolConfig.PublicIPNodePool = publicIpNodePool
}

kubernetesCluster, err := client.CreateKubernetesClusterPool(kubernetesFindCluster.ID, &poolConfig)
kubernetesCluster, err := client.CreateKubernetesClusterPool(kubernetesFindCluster.ID, &civogo.KubernetesClusterPoolConfig{
Region: client.Region,
ID: poolID,
Count: numTargetNodesPool,
Size: targetNodesPoolSize,
PublicIPNodePool: publicIpNodePool,
})
if err != nil {
utility.Error("%s", err)
os.Exit(1)
Expand Down
24 changes: 9 additions & 15 deletions cmd/kubernetes/kubernetes_nodepool_scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ var kubernetesNodePoolScaleCmd = &cobra.Command{
}

nodePoolFound := false
for _, pool := range kubernetesFindCluster.Pools {
for _, pool := range kubernetesFindCluster.RequiredPools {
if strings.Contains(pool.ID, nodePoolID) {
nodePoolID = pool.ID
nodePoolFound = true
break
}
}

Expand All @@ -63,32 +64,25 @@ var kubernetesNodePoolScaleCmd = &cobra.Command{
os.Exit(1)
}

nodePool := []civogo.KubernetesClusterPoolConfig{}
for _, v := range kubernetesFindCluster.Pools {
nodePool = append(nodePool, civogo.KubernetesClusterPoolConfig{ID: v.ID, Count: v.Count, Size: v.Size})
}

nodePool = utility.UpdateNodePool(nodePool, nodePoolID, numTargetNodesPoolScale)

configKubernetes := &civogo.KubernetesClusterConfig{
Pools: nodePool,
}

kubernetesCluster, err := client.UpdateKubernetesCluster(kubernetesFindCluster.ID, configKubernetes)
_, err = client.UpdateKubernetesClusterPool(kubernetesFindCluster.ID, nodePoolID, &civogo.KubernetesClusterPoolUpdateConfig{
ID: nodePoolID,
Count: &numTargetNodesPoolScale,
Region: client.Region,
})
if err != nil {
utility.Error("%s", err)
os.Exit(1)
}

ow := utility.NewOutputWriterWithMap(map[string]string{"id": kubernetesCluster.ID, "name": kubernetesCluster.Name, "pool_id": nodePoolID})
ow := utility.NewOutputWriterWithMap(map[string]string{"id": kubernetesFindCluster.ID, "name": kubernetesFindCluster.Name, "pool_id": nodePoolID})

switch common.OutputFormat {
case "json":
ow.WriteSingleObjectJSON(common.PrettySet)
case "custom":
ow.WriteCustomOutput(common.OutputFields)
default:
fmt.Printf("The pool (%s) was scaled to (%s) in the cluster (%s)\n", utility.Green(nodePoolID), utility.Green(strconv.Itoa(numTargetNodesPoolScale)), utility.Green(kubernetesCluster.Name))
fmt.Printf("The pool (%s) was scaled to (%s) in the cluster (%s)\n", utility.Green(nodePoolID), utility.Green(strconv.Itoa(numTargetNodesPoolScale)), utility.Green(kubernetesFindCluster.Name))
}
},
}
3 changes: 3 additions & 0 deletions cmd/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubernetes

import (
"reflect"
"sort"
"testing"
)

Expand Down Expand Up @@ -36,6 +37,8 @@ func TestInstallApplications(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := InstallApps(tt.args.defaultApps, tt.args.apps, tt.args.removeApps)
sort.Strings(tt.want)
sort.Strings(got)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("InstallApps() = %v, want %v", got, tt.want)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/volume/volume_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/briandowns/spinner"
"github.com/civo/civogo"
"github.com/civo/cli/common"
"github.com/civo/cli/config"
"github.com/civo/cli/utility"
Expand Down Expand Up @@ -61,7 +62,10 @@ var volumeAttachCmd = &cobra.Command{
os.Exit(1)
}

_, err = client.AttachVolume(volume.ID, instance.ID)
_, err = client.AttachVolume(volume.ID, civogo.VolumeAttachConfig{
InstanceID: instance.ID,
Region: client.Region,
})
if err != nil {
utility.Error("error attaching the volume: %s", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/briandowns/spinner v1.11.1
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c // indirect
github.com/civo/civogo v0.3.74
github.com/civo/civogo v0.3.77
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/google/go-github v17.0.0+incompatible // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ github.com/briandowns/spinner v1.11.1/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c h1:aprLqMn7gSPT+vdDSl+/E6NLEuArwD/J7IWd8bJt5lQ=
github.com/c4milo/unpackit v0.0.0-20170704181138-4ed373e9ef1c/go.mod h1:Ie6SubJv/NTO9Q0UBH0QCl3Ve50lu9hjbi5YJUw03TE=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/civo/civogo v0.3.73 h1:thkNnkziU+xh+MEOChIUwRZI1forN20+SSAPe/VFDME=
github.com/civo/civogo v0.3.73/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM=
github.com/civo/civogo v0.3.74 h1:MPrInhgOIuNOfcg1soyX2pm2L0nUa3/+No5hEgFgAuc=
github.com/civo/civogo v0.3.74/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM=
github.com/civo/civogo v0.3.77 h1:1rl5cpQruPhh+w8BBMpGQsaovjDvA44udPoDTAa45rk=
github.com/civo/civogo v0.3.77/go.mod h1:7UCYX+qeeJbrG55E1huv+0ySxcHTqq/26FcHLVelQJM=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down
2 changes: 1 addition & 1 deletion utility/output_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestWriteCustomOutput(t *testing.T) {
}

// TestExampleFWriteCustomOutput shows how to use the WriteCustomOutput function
func TestExampleFWriteCustomOutput() {
func TestExampleFWriteCustomOutput(t *testing.T) {
ow := NewOutputWriter()
// Write 3 lines and assert correct result
ow.StartLine()
Expand Down

0 comments on commit 3b7f3e2

Please sign in to comment.