Skip to content

Commit

Permalink
fix: Introduces wait polling in case we are waiting for the deletion. F…
Browse files Browse the repository at this point in the history
…ixes #109 (#153)
  • Loading branch information
alekc authored Jun 30, 2022
1 parent f17db98 commit 8e4af59
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion kubernetes/resource_kubectl_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,14 +636,29 @@ func resourceKubectlManifestDelete(ctx context.Context, d *schema.ResourceData,
log.Printf("[INFO] %s perform delete of manifest", manifest)

propagationPolicy := meta_v1.DeletePropagationBackground
if d.Get("wait").(bool) {
waitForDelete := d.Get("wait").(bool)
if waitForDelete {
propagationPolicy = meta_v1.DeletePropagationForeground
}
err = restClient.ResourceInterface.Delete(ctx, manifest.GetName(), meta_v1.DeleteOptions{PropagationPolicy: &propagationPolicy})
resourceGone := errors.IsGone(err) || errors.IsNotFound(err)
if err != nil && !resourceGone {
return fmt.Errorf("%v failed to delete kubernetes resource: %+v", manifest, err)
}
// at the moment the foreground propagation policy does not behave as expected (it won't block waiting for deletion
// and it's up to us to check that the object has been successfully deleted.
for waitForDelete {
_, err := restClient.ResourceInterface.Get(ctx, manifest.GetName(), meta_v1.GetOptions{})
resourceGone = errors.IsGone(err) || errors.IsNotFound(err)
if err != nil {
if resourceGone {
break
}
return fmt.Errorf("%v failed to delete kubernetes resource: %+v", manifest, err)
}
log.Printf("[DEBUG] %v waiting for deletion of the resource:\n%s", manifest, yamlBody)
time.Sleep(time.Second * 10)
}

// Success remove it from state
d.SetId("")
Expand Down

0 comments on commit 8e4af59

Please sign in to comment.