Skip to content

Commit dcb85d0

Browse files
author
Moritz Clasmeier
committed
Preserve finalizer modifications
1 parent 53f4003 commit dcb85d0

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

pkg/reconciler/internal/updater/updater.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,16 @@ func (u *Updater) tryRefreshObject(ctx context.Context, obj *unstructured.Unstru
210210

211211
// Overwrite metadata with the most recent in-cluster version.
212212
// This ensures we have the latest resourceVersion, annotations, labels, etc.
213-
objCopy.Object["metadata"] = current.Object["metadata"]
213+
// The reconciler flow can modify the set of finalizers, hence we need to preserve them.
214+
newMetadata, metadataFound, _ := unstructured.NestedFieldNoCopy(current.Object, "metadata")
215+
if !metadataFound {
216+
return false, fmt.Errorf("failed to obtain metadata from current object")
217+
}
218+
finalizers, finalizersFound, _ := unstructured.NestedFieldNoCopy(obj.Object, "metadata", "finalizers")
219+
if finalizersFound {
220+
unstructured.SetNestedField(newMetadata.(map[string]interface{}), finalizers, "finalizers")
221+
}
222+
objCopy.Object["metadata"] = newMetadata
214223

215224
// We were able to resolve the conflict by merging external conditions.
216225
obj.Object = objCopy.Object

0 commit comments

Comments
 (0)