Skip to content

Commit

Permalink
add mci finalizer with patch operation
Browse files Browse the repository at this point in the history
Signed-off-by: changzhen <changzhen5@huawei.com>
  • Loading branch information
XiShanYongYe-Chang committed Apr 2, 2024
1 parent 1207b03 commit d4fab7f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/controllers/multiclusteringress/mci_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
if finalizersUpdated {
err := c.Client.Update(ctx, mci)
if !controllerutil.ContainsFinalizer(mci, MCIControllerFinalizer) {
objPatch := client.MergeFrom(mci)
modifiedObj := mci.DeepCopy()
controllerutil.AddFinalizer(modifiedObj, MCIControllerFinalizer)
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
Expand Down

0 comments on commit d4fab7f

Please sign in to comment.