Skip to content

Commit

Permalink
[internal] Clean up deletion logic (#2460)
Browse files Browse the repository at this point in the history
The minimum supported Kubernetes version is now v1.13+, so simplify the deletion logic by removing special case for <v1.6 clusters.
  • Loading branch information
lblackstone committed Jun 23, 2023
1 parent fe413c8 commit 83b0247
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions provider/pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func Deletion(c DeleteConfig) error {
return nilIfGVKDeleted(err)
}

err = deleteResource(c.Context, c.Name, client, cluster.TryGetServerVersion(c.ClientSet.DiscoveryClientCached))
err = deleteResource(c.Context, c.Name, client)
if err != nil {
return nilIfGVKDeleted(err)
}
Expand Down Expand Up @@ -672,22 +672,14 @@ func Deletion(c DeleteConfig) error {
return waitErr
}

func deleteResource(
ctx context.Context, name string, client dynamic.ResourceInterface, version cluster.ServerVersion) error {
// Manually set delete propagation for Kubernetes versions < 1.6 to avoid bugs.
deleteOpts := metav1.DeleteOptions{}
if version.Compare(cluster.ServerVersion{Major: 1, Minor: 6}) < 0 {
// 1.5.x option.
boolFalse := false
// nolint
deleteOpts.OrphanDependents = &boolFalse
} else {
fg := metav1.DeletePropagationForeground
deleteOpts.PropagationPolicy = &fg
// deleteResource deletes the specified resource using foreground cascading delete.
func deleteResource(ctx context.Context, name string, client dynamic.ResourceInterface) error {
fg := metav1.DeletePropagationForeground
deleteOpts := metav1.DeleteOptions{
PropagationPolicy: &fg,
}

// Issue deletion request.
return client.Delete(ctx, name, *&deleteOpts)
return client.Delete(ctx, name, deleteOpts)
}

// checkIfResourceDeleted attempts to get a k8s resource, and returns true if the resource is not found (was deleted).
Expand Down

0 comments on commit 83b0247

Please sign in to comment.