Skip to content
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

Merged
merged 13 commits into from
Jun 14, 2021
Merged

Fix status update #96

merged 13 commits into from
Jun 14, 2021

Conversation

nebojsa-prodana
Copy link
Contributor

Fixes #93

Copy link
Contributor

@maruina maruina left a 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.

api/v1alpha1/condition_types.go Outdated Show resolved Hide resolved
controllers/progressivesync_controller.go Outdated Show resolved Hide resolved
return err
}
latest.Status = pr.Status
if err := r.Client.Status().Update(ctx, &latest); err != nil {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

internal/scheduler/scheduler.go Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Jun 8, 2021

This pull request introduces 1 alert when merging 1659d04 into 7f4bbae - view on LGTM.com

new alerts:

  • 1 for Useless assignment to local variable

@nebojsa-prodana
Copy link
Contributor Author

  • Useless assignment to local variable

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 {
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r.Log.Error(err, "failed to update object status")
log.Error(err, "failed to update object status")

@sledigabel
Copy link
Collaborator

Quick summary of our conversation:

  1. refactor the min calculation
  2. check out all the r.Log and see if they can just be log.
  3. refactor the initializeStatus to be closer to the format of the one in the helm controller: https://github.com/fluxcd/helm-controller/blob/e25d6894bfdc547101e60dbaf739f99ab4f005ef/controllers/helmrelease_controller.go#L184
  4. same for submitStatus

3 and 4 should fix the problem we're seeing at the linting phase.
@maruina could pick this up in @nebojsa-prodana 's absence

}

// reconcileStage reconcile a ProgressiveSyncStage
func (r *ProgressiveSyncReconciler) reconcileStage(ctx context.Context, ps syncv1alpha1.ProgressiveSync, stage syncv1alpha1.ProgressiveSyncStage) (syncv1alpha1.ProgressiveSync, reconcile.Result, error, bool) {
Copy link
Contributor

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. 🙂

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Collaborator

@sledigabel sledigabel left a 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.

controllers/progressivesync_controller.go Show resolved Hide resolved
@maruina maruina merged commit adcdbca into main Jun 14, 2021
@maruina maruina deleted the fix-status-update branch August 6, 2021 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reset ProgressiveSync object
4 participants