-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not retry updates on conflict #217
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -521,8 +521,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl. | |||||
return ctrl.Result{}, err | ||||||
} | ||||||
|
||||||
shouldUpdate := true | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Introducing a new variable here that is ready by the defer closure (and not easy to grok straight away), I think it might be cleaner to introduce a method on the updater such as
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this a lot 💯 |
||||||
u := updater.New(r.client) | ||||||
defer func() { | ||||||
if !shouldUpdate { | ||||||
return | ||||||
} | ||||||
applyErr := u.Apply(ctx, obj) | ||||||
if err == nil && !apierrors.IsNotFound(applyErr) { | ||||||
err = applyErr | ||||||
|
@@ -567,8 +571,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl. | |||||
u.UpdateStatus(updater.EnsureCondition(conditions.Initialized(corev1.ConditionTrue, "", ""))) | ||||||
|
||||||
if obj.GetDeletionTimestamp() != nil { | ||||||
err := r.handleDeletion(ctx, actionClient, obj, log) | ||||||
return ctrl.Result{}, err | ||||||
if err := r.handleDeletion(ctx, actionClient, obj, log); err != nil { | ||||||
return ctrl.Result{}, err | ||||||
everettraven marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
shouldUpdate = false | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is slightly different from the case described in the PR description, right? |
||||||
return ctrl.Result{}, nil | ||||||
} | ||||||
|
||||||
vals, err := r.getValues(ctx, obj) | ||||||
|
@@ -660,28 +667,27 @@ const ( | |||||
) | ||||||
|
||||||
func (r *Reconciler) handleDeletion(ctx context.Context, actionClient helmclient.ActionInterface, obj *unstructured.Unstructured, log logr.Logger) error { | ||||||
if !controllerutil.ContainsFinalizer(obj, uninstallFinalizer) { | ||||||
log.Info("Resource is terminated, skipping reconciliation") | ||||||
return nil | ||||||
} | ||||||
|
||||||
// Use defer in a closure so that it executes before we wait for | ||||||
// the deletion of the CR. This might seem unnecessary since we're | ||||||
// applying changes to the CR after is has a deletion timestamp. | ||||||
// However, if uninstall fails, the finalizer will not be removed | ||||||
// and we need to be able to update the conditions on the CR to | ||||||
// indicate that the uninstall failed. | ||||||
if err := func() (err error) { | ||||||
uninstallUpdater := updater.New(r.client) | ||||||
defer func() { | ||||||
applyErr := uninstallUpdater.Apply(ctx, obj) | ||||||
if err == nil { | ||||||
err = applyErr | ||||||
} | ||||||
}() | ||||||
return r.doUninstall(actionClient, &uninstallUpdater, obj, log) | ||||||
}(); err != nil { | ||||||
return err | ||||||
if controllerutil.ContainsFinalizer(obj, uninstallFinalizer) { | ||||||
// Use defer in a closure so that it executes before we wait for | ||||||
// the deletion of the CR. This might seem unnecessary since we're | ||||||
// applying changes to the CR after is has a deletion timestamp. | ||||||
// However, if uninstall fails, the finalizer will not be removed | ||||||
// and we need to be able to update the conditions on the CR to | ||||||
// indicate that the uninstall failed. | ||||||
if err := func() (err error) { | ||||||
uninstallUpdater := updater.New(r.client) | ||||||
defer func() { | ||||||
applyErr := uninstallUpdater.Apply(ctx, obj) | ||||||
if err == nil { | ||||||
err = applyErr | ||||||
} | ||||||
}() | ||||||
return r.doUninstall(actionClient, &uninstallUpdater, obj, log) | ||||||
}(); err != nil { | ||||||
return err | ||||||
} | ||||||
} else { | ||||||
log.Info("Resource is already terminated, skipping deletion") | ||||||
everettraven marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
// Since the client is hitting a cache, waiting for the | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit awkward, because these two new comment lines applies to both
retry.OnError
calls. However the above 3 lines only apply to the firstretry.OnError
call.I can suggest two solutions:
OnError
call, which is not great.and then we could put this comment on this function, which would be the most appropriate place. We could optionally also inline
isRetryableUpdateError
in that case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good :)