Skip to content

Commit ba3a083

Browse files
committed
Ensure SSA patch can't accidentally create a new object
This fixes a race during image delete where we can get a second reconcile on a deleted object and accidentally create a new object when we only intended to remove the finalizer from the old object. With this change, the second patch will throw an error instead.
1 parent 6560f88 commit ba3a083

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

internal/controllers/image/reconcile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (r *orcImageReconciler) reconcileDelete(ctx context.Context, orcImage *orcv
232232
log.V(4).Info("Image is deleted")
233233

234234
// Clear owned fields on the base resource, including the finalizer
235-
applyConfig := orcapplyconfigv1alpha1.Image(orcImage.Name, orcImage.Namespace)
235+
applyConfig := orcapplyconfigv1alpha1.Image(orcImage.Name, orcImage.Namespace).WithUID(orcImage.UID)
236236
return ctrl.Result{}, r.client.Patch(ctx, orcImage, ssa.ApplyConfigPatch(applyConfig), client.ForceOwnership, client.FieldOwner(orcv1alpha1.ImageControllerFieldOwner))
237237
}
238238

internal/controllers/image/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545
// updateObject writes to the Image root resource, i.e. everything except status.
4646
func (r *orcImageReconciler) updateObject(ctx context.Context, orcImage *orcv1alpha1.Image) error {
4747
applyConfig := orcapplyconfigv1alpha1.Image(orcImage.Name, orcImage.Namespace).
48-
WithFinalizers(orcv1alpha1.ImageControllerFinalizer)
48+
WithFinalizers(orcv1alpha1.ImageControllerFinalizer).WithUID(orcImage.UID)
4949

5050
return r.client.Patch(ctx, orcImage, ssa.ApplyConfigPatch(applyConfig), client.ForceOwnership, client.FieldOwner(orcv1alpha1.ImageControllerFieldOwner))
5151
}

0 commit comments

Comments
 (0)