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

Implementing promotion algorithm defined in level-triggered architecture rfc #203

Merged
merged 1 commit into from
Oct 26, 2023

Conversation

luizbafilho
Copy link
Contributor

@luizbafilho luizbafilho commented Oct 13, 2023

Implements the algorithm defined in level-triggered architecture rfc.

Notes:

  • It does not handle any of the promotion strategies. Those are not idempotent right now, so running them as is will cause unexpected issues.
  • replaces github.com/golang/mock with go.uber.org/mock since the former is now unmaintained.

Closes #195

@luizbafilho luizbafilho marked this pull request as ready for review October 13, 2023 15:03
Copy link
Contributor

@yitsushi yitsushi left a comment

Choose a reason for hiding this comment

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

A small simplification suggestion, but overall looks good to me. For the simplifications, obviously one of them as they conflict with each other.

I don't know if it's important to check first env separately (like you have other plans in the future that would be easier to have it as a separate check.

return ctrl.Result{}, nil
}

for i := 1; i < len(pipeline.Spec.Environments); i++ {
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 we can use a simple range here, I don't see i is use anyone where.

for _, env := range pipeline.Spec.Environments[1:] {
  // ...
}

@@ -182,9 +185,74 @@ func (r *PipelineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
pipeline.GetNamespace(), pipeline.GetName(),
)

firstEnv := pipeline.Spec.Environments[0]

ok, latestRevision := checkAllTargetsHaveSameRevision(pipeline.Status.Environments[firstEnv.Name])
Copy link
Contributor

Choose a reason for hiding this comment

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

If latestRevision is set to empty string, we can merge this into the loop below and the check would be something like:

		ok, revision := checkAllTargetsHaveSameRevision(pipeline.Status.Environments[env.Name])
		if !ok {
			// not all targets have the same revision, so we can't proceed
			return ctrl.Result{}, nil
		}

		if latestRevision == "" {
			latestRevision = revision
			continue
		}

		if revision != latestRevision {
			// the same as you have now.
		}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, that would work, thanks

Copy link
Contributor

@squaremo squaremo left a comment

Choose a reason for hiding this comment

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

👍 for keeping this low impact (it doesn't splat across lots of files) and pretty accurate. I think the definition for when to trigger a promotion needs another iteration -- see my comment on controller.go#L199. If you can demonstrate that working as described, with tests (see comment on controller_test.go), we're there.
It's worth putting in a guard against nil pointer deference, too. The other comment, on checkAllTargets....(), is just commentary -- do whatever works :-)

controllers/leveltriggered/controller.go Outdated Show resolved Hide resolved
controllers/leveltriggered/controller.go Outdated Show resolved Hide resolved
controllers/leveltriggered/controller.go Outdated Show resolved Hide resolved
controllers/leveltriggered/controller_test.go Show resolved Hide resolved
@squaremo
Copy link
Contributor

  • It does not handle any of the promotion strategies. Those are not idempotent right now, so running them as is will cause unexpected issues.

That's fine, making promotion actions work reliably is the subject of #197.

Copy link
Contributor

@squaremo squaremo left a comment

Choose a reason for hiding this comment

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

Thanks for following up on those previous comments. The way you've structured the algorithm, with the checkAll, checkAny, etc., makes it clear what's happening. Should it break if it successfully calls promote?

controllers/leveltriggered/controller.go Show resolved Hide resolved
api/v1alpha1/conditions.go Outdated Show resolved Hide resolved
controllers/leveltriggered/controller_test.go Show resolved Hide resolved
controllers/leveltriggered/controller_test.go Outdated Show resolved Hide resolved
controllers/leveltriggered/controller.go Outdated Show resolved Hide resolved
controllers/leveltriggered/controller_test.go Show resolved Hide resolved
Copy link
Contributor

@squaremo squaremo left a comment

Choose a reason for hiding this comment

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

All of my changes / comments have been addressed, thanks @luizbafilho. I think it's worth spending no more than an hour tidying, squashing fixups and making sure the git commits have good messages, before merging. This is a bit big to be one squashed merge.

Copy link
Contributor

@yitsushi yitsushi left a comment

Choose a reason for hiding this comment

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

lgtm

@luizbafilho luizbafilho merged commit 78b95a7 into main Oct 26, 2023
6 checks passed
@luizbafilho luizbafilho deleted the 195-rewrite-promotion-algo branch October 26, 2023 14:16
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.

Rewrite the promotion algorithm, using stubs for promotions
3 participants