Skip to content

Commit c02afe0

Browse files
authored
Merge pull request #2178 from shiftstack/image-finalizer
🐛 Ensure SSA patch can't accidentally create a new object
2 parents 1e39a38 + ba3a083 commit c02afe0

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
@@ -241,7 +241,7 @@ func (r *orcImageReconciler) reconcileDelete(ctx context.Context, orcImage *orcv
241241
log.V(4).Info("Image is deleted")
242242

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

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)