-
Notifications
You must be signed in to change notification settings - Fork 4
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
Fix status update #96
Conversation
dd68e91
to
ca87e60
Compare
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.
Some questions but looks promising.
return err | ||
} | ||
latest.Status = pr.Status | ||
if err := r.Client.Status().Update(ctx, &latest); err != nil { |
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.
Why are we dropping the r.Client.Status().Patch(ctx, pr, client.MergeFrom(&latest))
and use Status().Update
instead?
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.
We don't need to merge anymore, because we already have the latest state retrieved, so we can just update instead.
This pull request introduces 1 alert when merging 1659d04 into 7f4bbae - view on LGTM.com new alerts:
|
Seems like a false alert to me, the pr object is updated through pass by reference in the caller's code. |
// patchStatus patches the progressive sync object status | ||
func (r *ProgressiveSyncReconciler) patchStatus(ctx context.Context, pr *syncv1alpha1.ProgressiveSync) error { | ||
// submitStatus updates the progressive sync object status with backoff | ||
func (r *ProgressiveSyncReconciler) submitStatus(ctx context.Context, pr *syncv1alpha1.ProgressiveSync) error { |
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.
Why not updateStatus
?
r.updateStageStatus(ctx, stage.Name, message, syncv1alpha1.PhaseUnknown, &pr) | ||
|
||
if err := r.submitStatus(ctx, &pr); err != nil { | ||
r.Log.Error(err, "failed to update object status") |
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.
r.Log.Error(err, "failed to update object status") | |
log.Error(err, "failed to update object status") |
Quick summary of our conversation:
3 and 4 should fix the problem we're seeing at the linting phase. |
41699f9
to
48e7d6e
Compare
} | ||
|
||
// reconcileStage reconcile a ProgressiveSyncStage | ||
func (r *ProgressiveSyncReconciler) reconcileStage(ctx context.Context, ps syncv1alpha1.ProgressiveSync, stage syncv1alpha1.ProgressiveSyncStage) (syncv1alpha1.ProgressiveSync, reconcile.Result, error, bool) { |
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.
I'm not a fan of returning four different values, to be honest. I'm aware that it's idiomatic Go to return two values, with one being for error-handling, but having two additional return values makes this difficult to follow.
I think as a starting point, perhaps named return values (if at all possible?) and definitely adding documentation would make this better, as it's not immediately clear what the bool
value means.
Further refactoring to avoid 3 non-error return values would probably be beneficial, but I understand if we'd rather do that later. 🙂
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.
Well, I just saw https://github.com/fluxcd/helm-controller/blob/e25d6894bfdc547101e60dbaf739f99ab4f005ef/controllers/helmrelease_controller.go#L184 that Seb linked and can see they have 3 returns values (2 + error) - so this isn't a 'first' 🙂
I'm still not overly fond of multiple return values, but at least naming and/or documenting them something would be a good first step.
Truth is, the whole reconciliation loop has multiple responsibilities - or at least a wide scope of responsibility -, making it harder to have a single return value.
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.
I was able to remove a variable because we can use result.Requeue
to see if we need to requeue or not.
I don't think we can remove the ProgressiveSync variable unless we start doing things with pointer, but we decided to follow a value semantic.
Are you happy with the latest implementation? Is there anything else do you think we can improve?
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.
Yea, looks good 👍
@@ -394,19 +293,14 @@ func (r *ProgressiveSyncReconciler) removeAnnotationFromApps(ctx context.Context | |||
} | |||
|
|||
// updateStageStatus updates the target stage given a stage name, message and phase | |||
func (r *ProgressiveSyncReconciler) updateStageStatus(ctx context.Context, name, message string, phase syncv1alpha1.StageStatusPhase, pr *syncv1alpha1.ProgressiveSync) error { | |||
func (r *ProgressiveSyncReconciler) updateStageStatus(ctx context.Context, name, message string, phase syncv1alpha1.StageStatusPhase, pr *syncv1alpha1.ProgressiveSync) { |
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.
Why have we removed the error
return value here?
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.
I think it's because pr.SetStageStatus
doesn't return anything and we now make the update while calling updateStatusWithRetry
.
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.
LGTM
well done all, great opportunity to fix a bug and refactor.
Fixes #93