Skip to content

Commit

Permalink
ACM-5399: Use update instead of SSA for MCE subscription (stolostron#…
Browse files Browse the repository at this point in the history
…1038)

* Use update instead of SSA for MCE subscription

If config is defined in the subscription and then removed, the patch
operation will fail because it will try to patch with null.

Signed-off-by: Jakob Gray <[email protected]>

* Distinguish create and update

Signed-off-by: Jakob Gray <[email protected]>

---------

Signed-off-by: Jakob Gray <[email protected]>
  • Loading branch information
JakobGray authored May 30, 2023
1 parent 92ddff8 commit 2d5a2a5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ func (r *MultiClusterHubReconciler) ensureMCESubscription(ctx context.Context, m
}
}

createSub := false
if mceSub == nil {
result, err := r.ensureNamespace(multiClusterHub, multiclusterengine.Namespace())
if result != (ctrl.Result{}) {
Expand All @@ -527,6 +528,7 @@ func (r *MultiClusterHubReconciler) ensureMCESubscription(ctx context.Context, m
}
// Sub is nil so create a new one
mceSub = multiclusterengine.NewSubscription(multiClusterHub, subConfig, overrides, utils.IsCommunityMode())
createSub = true
} else if multiclusterengine.CreatedByMCH(mceSub, multiClusterHub) {
result, err := r.ensurePullSecret(multiClusterHub, multiclusterengine.Namespace().Name)
if result != (ctrl.Result{}) {
Expand All @@ -540,13 +542,15 @@ func (r *MultiClusterHubReconciler) ensureMCESubscription(ctx context.Context, m

// Apply MCE sub
calcSub := multiclusterengine.RenderSubscription(mceSub, subConfig, overrides, ctlSrc, utils.IsCommunityMode())

force := true
err = r.Client.Patch(ctx, calcSub, client.Apply, &client.PatchOptions{Force: &force, FieldManager: "multiclusterhub-operator"})
if createSub {
err = r.Client.Create(ctx, calcSub)
} else {
err = r.Client.Update(ctx, calcSub)
}
if err != nil {
r.Log.Info(fmt.Sprintf("Error applying subscription: %s", err.Error()))
return ctrl.Result{Requeue: true}, err
return ctrl.Result{Requeue: true}, fmt.Errorf("Error updating subscription %s: %w", calcSub.Name, err)
}

return ctrl.Result{}, nil
}

Expand Down

0 comments on commit 2d5a2a5

Please sign in to comment.