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 orphan_resource_on_delete argument to worker pool resources #5705

Merged
merged 6 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 23 additions & 9 deletions ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ func ResourceIBMContainerVpcWorkerPool() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
DiffSuppressFunc: flex.ApplyOnce,
Description: "Import an existing WorkerPool from the cluster, instead of creating a new",
Description: "Import an existing workerpool from the cluster instead of creating a new",
},

"orphan_on_delete": {
Type: schema.TypeBool,
Optional: true,
Description: "Orphan the workerpool resource instead of deleting it",
},

"autoscale_enabled": {
Expand Down Expand Up @@ -715,14 +721,22 @@ func resourceIBMContainerVpcWorkerPoolDelete(d *schema.ResourceData, meta interf
if err != nil {
return err
}

err = workerPoolsAPI.DeleteWorkerPool(clusterNameorID, workerPoolNameorID, targetEnv)
if err != nil {
return err
var orphan_resource bool = false
if orod, ok := d.GetOk("orphan_on_delete"); ok {
orphan_resource = orod.(bool)
}
_, err = WaitForVpcWorkerDelete(clusterNameorID, workerPoolNameorID, meta, d.Timeout(schema.TimeoutDelete), targetEnv)
if err != nil {
return fmt.Errorf("[ERROR] Error waiting for removing workers of worker pool (%s) of cluster (%s): %s", workerPoolNameorID, clusterNameorID, err)

if orphan_resource {
log.Printf("[WARN] orphaning %s workerpool", workerPoolNameorID)
} else {
err = workerPoolsAPI.DeleteWorkerPool(clusterNameorID, workerPoolNameorID, targetEnv)
if err != nil {
return err
}
_, err = WaitForVpcWorkerDelete(clusterNameorID, workerPoolNameorID, meta, d.Timeout(schema.TimeoutDelete), targetEnv)
if err != nil {
return fmt.Errorf("[ERROR] Error waiting for removing workers of worker pool (%s) of cluster (%s): %s", workerPoolNameorID, clusterNameorID, err)
}
}
d.SetId("")
return nil
Expand Down Expand Up @@ -788,7 +802,7 @@ func WaitForWorkerPoolAvailable(d *schema.ResourceData, meta interface{}, cluste

func vpcWorkerPoolStateRefreshFunc(client v2.Workers, instanceID string, workerPoolNameOrID string, target v2.ClusterTargetHeader) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
workerFields, err := client.ListByWorkerPool(instanceID, "", false, target)
workerFields, err := client.ListByWorkerPool(instanceID, workerPoolNameOrID, false, target)
if err != nil {
return nil, "", fmt.Errorf("[ERROR] Error retrieving workers for cluster: %s", err)
}
Expand Down
Loading
Loading