From a86c95a5ada370ef07ce71ca68e8b8af167a3092 Mon Sep 17 00:00:00 2001 From: changzhen Date: Tue, 2 Apr 2024 10:27:27 +0800 Subject: [PATCH] add mci finalizer with patch operation Signed-off-by: changzhen --- pkg/controllers/multiclusteringress/mci_controller.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/controllers/multiclusteringress/mci_controller.go b/pkg/controllers/multiclusteringress/mci_controller.go index 90fd208..79cf573 100644 --- a/pkg/controllers/multiclusteringress/mci_controller.go +++ b/pkg/controllers/multiclusteringress/mci_controller.go @@ -91,9 +91,11 @@ func (c *MCIController) handleMCIDelete(ctx context.Context, mci *networkingv1al func (c *MCIController) handleMCICreateOrUpdate(ctx context.Context, mci *networkingv1alpha1.MultiClusterIngress) (controllerruntime.Result, error) { klog.V(4).InfoS("Begin to handle multiClusterIngress create or update event", "namespace", mci.Namespace, "name", mci.Name) - finalizersUpdated := controllerutil.AddFinalizer(mci, MCIControllerFinalizer) + objPatch := client.MergeFrom(mci) + modifiedObj := mci.DeepCopy() + finalizersUpdated := controllerutil.AddFinalizer(modifiedObj, MCIControllerFinalizer) if finalizersUpdated { - err := c.Client.Update(ctx, mci) + err := c.Client.Patch(ctx, modifiedObj, objPatch) if err != nil { klog.V(4).ErrorS(err, "failed to update mci with finalizer", "namespace", mci.Namespace, "name", mci.Name) return controllerruntime.Result{}, err