Skip to content

Commit

Permalink
Fixed error when you change the node pool count (#165)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro J. Nuñez Madrazo <alejandrojnm@gmail.com>
  • Loading branch information
alejandrojnm committed Feb 13, 2023
1 parent aff3fc3 commit 86541ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion civo/resource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func resourceKubernetesClusterUpdate(ctx context.Context, d *schema.ResourceData
return diag.Errorf("[ERR] failed to update kubernetes cluster: %s", err)
}

err = waitForKubernetesNodePoolCreate(apiClient, d)
err = waitForKubernetesNodePoolCreate(apiClient, d, d.Id())
if err != nil {
return diag.Errorf("Error updating Kubernetes node pool: %s", err)
}
Expand Down Expand Up @@ -527,6 +527,7 @@ func flattenInstalledApplication(apps []civogo.KubernetesInstalledApplication) [
return flattenedInstalledApplication
}

// exapandNodePools function to expand the node pools
func expandNodePools(nodePools []interface{}) []civogo.KubernetesClusterPoolConfig {
expandedNodePools := make([]civogo.KubernetesClusterPoolConfig, 0, len(nodePools))
for _, rawPool := range nodePools {
Expand Down
8 changes: 3 additions & 5 deletions civo/resource_kubernetes_cluster_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func resourceKubernetesClusterNodePoolCreate(ctx context.Context, d *schema.Reso

d.SetId(nodePoolLabel)

err = waitForKubernetesNodePoolCreate(apiClient, d)
err = waitForKubernetesNodePoolCreate(apiClient, d, clusterID)
if err != nil {
return diag.Errorf("Error creating Kubernetes node pool: %s", err)
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func resourceKubernetesClusterNodePoolUpdate(ctx context.Context, d *schema.Reso
return diag.Errorf("[ERR] failed to update kubernetes cluster: %s", err)
}

err = waitForKubernetesNodePoolCreate(apiClient, d)
err = waitForKubernetesNodePoolCreate(apiClient, d, clusterID)
if err != nil {
return diag.Errorf("Error updating Kubernetes node pool: %s", err)
}
Expand Down Expand Up @@ -355,7 +355,7 @@ func updateNodePool(s []civogo.KubernetesClusterPoolConfig, id string, count int
}

// waitForKubernetesNodePoolCreate is a utility function to wait for a node pool to be created
func waitForKubernetesNodePoolCreate(client *civogo.Client, d *schema.ResourceData) error {
func waitForKubernetesNodePoolCreate(client *civogo.Client, d *schema.ResourceData, clusterID string) error {
var (
tickerInterval = 10 * time.Second
timeoutSeconds = d.Timeout(schema.TimeoutCreate).Seconds()
Expand All @@ -364,12 +364,10 @@ func waitForKubernetesNodePoolCreate(client *civogo.Client, d *schema.ResourceDa
totalRequiredInstance = 0
totalRunningInstance = 0
ticker = time.NewTicker(tickerInterval)
clusterID = d.Get("cluster_id").(string)
nodePoolID = d.Id()
)

for range ticker.C {

cluster, err := client.GetKubernetesCluster(clusterID)
if err != nil {
ticker.Stop()
Expand Down

0 comments on commit 86541ea

Please sign in to comment.