Skip to content

Commit d94752e

Browse files
committed
DRA resourceslice controller: use preconditions for Delete
It's better to verify UID and ResourceVersion of the ResourceSlice that we want to delete. If anything changed, the decision to remove it might not apply anymore and we need to check again.
1 parent a6d180c commit d94752e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

staging/src/k8s.io/dynamic-resource-allocation/resourceslice/resourceslicecontroller.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,22 @@ func (c *Controller) syncPool(ctx context.Context, poolName string) error {
605605

606606
// Remove stale slices.
607607
for _, slice := range obsoleteSlices {
608-
logger.V(5).Info("Deleting obsolete resource slice", "slice", klog.KObj(slice))
609-
if err := c.kubeClient.ResourceV1alpha3().ResourceSlices().Delete(ctx, slice.Name, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
608+
options := metav1.DeleteOptions{
609+
Preconditions: &metav1.Preconditions{
610+
UID: &slice.UID,
611+
ResourceVersion: &slice.ResourceVersion,
612+
},
613+
}
614+
// It can happen that we sync again shortly after deleting a
615+
// slice and before the slice gets removed from the informer
616+
// cache. The MutationCache can't help here because it does not
617+
// track pending deletes.
618+
//
619+
// If this happens, we get a "not found error" and nothing
620+
// changes on the server. The only downside is the extra API
621+
// call. This isn't as bad as extra creates.
622+
logger.V(5).Info("Deleting obsolete resource slice", "slice", klog.KObj(slice), "deleteOptions", options)
623+
if err := c.kubeClient.ResourceV1alpha3().ResourceSlices().Delete(ctx, slice.Name, options); err != nil && !apierrors.IsNotFound(err) {
610624
return fmt.Errorf("delete resource slice: %w", err)
611625
}
612626
}

0 commit comments

Comments
 (0)