Skip to content

Commit

Permalink
Merge pull request #55 from pluralsh/marcin/prod-2548-detach-call-on-…
Browse files Browse the repository at this point in the history
…terraform-cluster-delete-occasionally

fix: Fix polling logic in delete handlers
  • Loading branch information
maciaszczykm authored Aug 22, 2024
2 parents 4bbca78 + 93259b4 commit 4fd34ce
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
6 changes: 5 additions & 1 deletion internal/resource/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ func (r *clusterResource) Delete(ctx context.Context, req resource.DeleteRequest

if err = wait.PollUntilContextTimeout(ctx, 10*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
response, err := r.client.GetCluster(ctx, data.Id.ValueStringPointer())
if client.IsNotFound(err) || response == nil || response.Cluster == nil {
if client.IsNotFound(err) {
return true, nil
}

if err == nil && (response == nil || response.Cluster == nil) {
return true, nil
}

Expand Down
11 changes: 7 additions & 4 deletions internal/resource/infrastructure_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,18 @@ func (r *InfrastructureStackResource) Delete(ctx context.Context, req resource.D
return
}

err = wait.PollUntilContextCancel(ctx, 5*time.Second, true, func(ctx context.Context) (bool, error) {
_, err := r.client.GetInfrastructureStack(ctx, data.Id.ValueStringPointer(), nil)
if err = wait.PollUntilContextTimeout(ctx, 10*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
response, err := r.client.GetInfrastructureStack(ctx, data.Id.ValueStringPointer(), nil)
if client.IsNotFound(err) {
return true, nil
}

if err == nil && (response == nil || response.InfrastructureStack == nil) {
return true, nil
}

return false, err
})
if err != nil {
}); err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Error during watiting for infrastructure stack to be deleted, got error: %s", err))
return
}
Expand Down
11 changes: 7 additions & 4 deletions internal/resource/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,18 @@ func (r *providerResource) Delete(ctx context.Context, req resource.DeleteReques
return
}

err = wait.PollUntilContextCancel(ctx, 5*time.Second, true, func(ctx context.Context) (bool, error) {
_, err := r.client.GetClusterProvider(ctx, data.Id.ValueString())
if err = wait.PollUntilContextTimeout(ctx, 10*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
response, err := r.client.GetClusterProvider(ctx, data.Id.ValueString())
if client.IsNotFound(err) {
return true, nil
}

if err == nil && (response == nil || response.ClusterProvider == nil) {
return true, nil
}

return false, err
})
if err != nil {
}); err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Error while watiting for provider to be deleted, got error: %s", err))
return
}
Expand Down
11 changes: 7 additions & 4 deletions internal/resource/service_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,18 @@ func (r *ServiceDeploymentResource) Delete(ctx context.Context, req resource.Del
return
}

err = wait.PollUntilContextCancel(ctx, 5*time.Second, true, func(ctx context.Context) (bool, error) {
_, err := r.client.GetServiceDeployment(ctx, data.Id.ValueString())
if err = wait.PollUntilContextTimeout(ctx, 10*time.Second, 10*time.Minute, true, func(ctx context.Context) (bool, error) {
response, err := r.client.GetServiceDeployment(ctx, data.Id.ValueString())
if client.IsNotFound(err) {
return true, nil
}

if err == nil && (response == nil || response.ServiceDeployment == nil) {
return true, nil
}

return false, err
})
if err != nil {
}); err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Error during watiting for ServiceDeployment to be deleted, got error: %s", err))
return
}
Expand Down

0 comments on commit 4fd34ce

Please sign in to comment.