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

Flux source integration #324

Merged
merged 12 commits into from
Oct 11, 2022
Merged

Flux source integration #324

merged 12 commits into from
Oct 11, 2022

Conversation

squaremo
Copy link
Contributor

@squaremo squaremo commented Sep 13, 2022

Addresses #158.

  • Design for Flux source integration
    • Review that design and adapt
  • Implement!

This adds FluxSource as an alternative to the (inline) GitSource.

Signed-off-by: Michael Bridgen <[email protected]>
@squaremo squaremo force-pushed the flux-source-integration branch from b8e5b55 to f72adf4 Compare October 6, 2022 18:16
@squaremo
Copy link
Contributor Author

squaremo commented Oct 10, 2022

Further test cases:

  • When the referenced source is missing, the Stack fails and is marked retrying
  • [ ] When the source has a new version, the stack is rerun
  • If the source artifact URL cannot be fetched, the stack is failed and marked as retrying
  • If the Flux source is marked unready, this should be reflected in the Stack status; and once it's marked ready, the stack should be retried.

EDIT: I am going to bump "When the source has a new version, the stack is rerun". This is true, as a consequence of stacks being rescheduled, so it will work the same as a git source. It would be nice to keep a watch on sources and be more responsive than git sources (which poll the git repo for new commits on each run), but it can be done in a follow up PR, I think.

@squaremo squaremo force-pushed the flux-source-integration branch 2 times, most recently from d5ae2f3 to 3681dae Compare October 10, 2022 15:56
@squaremo squaremo requested a review from lblackstone October 10, 2022 16:27
@squaremo
Copy link
Contributor Author

(I will square away the design doc -- aside from anything else, the fields in the proposed API change need to be renamed)

pkg/controller/stack/flux.go Outdated Show resolved Hide resolved
pkg/controller/stack/stack_controller.go Outdated Show resolved Hide resolved
pkg/controller/stack/stack_controller.go Outdated Show resolved Hide resolved
test/flux_source_test.go Outdated Show resolved Hide resolved
This adds handling of Flux sources into the controller, while trying to
disturb the present behaviour as little as possible. Broadly this means
branching in a couple of places to do source-specific things: in
particular,

 - setting up the automation API workspace (SetupWorkdirFrom*) is mostly
   different up to the point you have fetched the source code, which in
   the GitSource case is done _by_ setting up the workspace; so, all the
   things you have to do _after_ you have an auto.Workspace go into
   another helper, which is called from each Setup func. The func
   signatures are brought into line so the return values can have a
   uniform treatment.

 - requeue handling is quite idiosyncratic (e.g,. why does
   ContinueResyncOnCommitMatch only matter if you are tracking a
   branch?). I have left the current behaviour for git sources intact,
   since it may be relied upon in deployments, and branched to analogous
   logic for Flux sources. This means some near-duplicated code, for the
   sake of playing it safe.

Signed-off-by: Michael Bridgen <[email protected]>
A missing source is something that could just "come right"; record it in
.status.lastUpdate as a failure, and in .status.conditions as "in
progress (retrying)".

Signed-off-by: Michael Bridgen <[email protected]>
Signed-off-by: Michael Bridgen <[email protected]>
Many of the tests wait for a particular value of
`.status.lastUpdate.State`, then check the values of conditions are as
expected. However, between these two things, they fetch the object from
the API server again (`refetch`), since the waitForStack* uses a
temporary variable rather than mutating the stack given to it. That that
admits the possibility that the status might have been updated again, by
the controller reconciling it again.

Instead, let waitForStack* write to the object it's given, and don't
`refetch` -- then, the status observed will be the status at the point
the wait succeeded.

Signed-off-by: Michael Bridgen <[email protected]>
This standardises how the .status.artifact.X fields are accessed, so
that (for the sake of a few extra lines) there's less repeated code, and
errors are consistent.

Signed-off-by: Michael Bridgen <[email protected]>
Previously, an if-then-else checked for the presence of source
specifications (GitSource and FluxSource), and this made it possible to
supply a stack object with both kinds of source (though only the first
checked -- GitSource -- would be used).

This commit makes that bit of code enforce the mutual exclusion of
sources.

Signed-off-by: Michael Bridgen <[email protected]>
@squaremo squaremo force-pushed the flux-source-integration branch from 531fe1c to fc4f6fc Compare October 11, 2022 10:38
@squaremo squaremo requested a review from lblackstone October 11, 2022 13:14
// Check which kind of source we have.
gitSource, fluxSource := stack.GitSource, stack.FluxSource
switch {
case gitSource != nil && fluxSource == nil:
Copy link
Member

Choose a reason for hiding this comment

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

This logic is fine, but an alternative would be validating the mutually-exclusive condition ahead of the switch, and then keeping the simpler non-nil selection logic that you had previously. It probably doesn't matter for this PR, but it might be a little cleaner once the inline YAML case is added as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am ever hopeful that a switch will help make the code look more like a pattern match. One day it'll be true.

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.

2 participants