@@ -116,17 +116,24 @@ func (r *ClusterExtensionReconciler) Reconcile(ctx context.Context, req ctrl.Req
116116 // Do checks before any Update()s, as Update() may modify the resource structure!
117117 updateStatus := ! equality .Semantic .DeepEqual (existingExt .Status , reconciledExt .Status )
118118 updateFinalizers := ! equality .Semantic .DeepEqual (existingExt .Finalizers , reconciledExt .Finalizers )
119+
120+ // If any unexpected fields have changed, panic before updating the resource
119121 unexpectedFieldsChanged := checkForUnexpectedFieldChange (* existingExt , * reconciledExt )
122+ if unexpectedFieldsChanged {
123+ panic ("spec or metadata changed by reconciler" )
124+ }
120125
126+ // Save the finalizers off to the side. If we update the status, the reconciledExt will be updated
127+ // to contain the new state of the ClusterExtension, which contains the status update, but (critically)
128+ // does not contain the finalizers. After the status update, we need to re-add the finalizers to the
129+ // reconciledExt before updating the object.
130+ finalizers := reconciledExt .Finalizers
121131 if updateStatus {
122132 if err := r .Client .Status ().Update (ctx , reconciledExt ); err != nil {
123133 updateError = errors .Join (updateError , fmt .Errorf ("error updating status: %v" , err ))
124134 }
125135 }
126-
127- if unexpectedFieldsChanged {
128- panic ("spec or metadata changed by reconciler" )
129- }
136+ reconciledExt .Finalizers = finalizers
130137
131138 if updateFinalizers {
132139 if err := r .Client .Update (ctx , reconciledExt ); err != nil {
0 commit comments