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

Watch Program and Flux sources and run a Stack when they change #348

Merged
merged 5 commits into from
Oct 25, 2022

Conversation

squaremo
Copy link
Contributor

@squaremo squaremo commented Oct 19, 2022

This uses the usual controller-runtime machinery to watch Program and Flux resources, and rerun any Stack that refers to a Program when it's changed.

In passing, I've fixed a problem with Program.program.configuration.default -- it wasn't properly optional.

Fixes #343.

@squaremo squaremo changed the title Watch Program sources and run a Stack when they change Watch Program and Flux sources and run a Stack when they change Oct 20, 2022
@squaremo squaremo requested a review from roothorp October 21, 2022 09:26
Copy link
Member

@lblackstone lblackstone left a comment

Choose a reason for hiding this comment

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

Functional changes LGTM. Just a couple small items

test/program_test.go Outdated Show resolved Hide resolved
pkg/controller/stack/stack_controller.go Outdated Show resolved Hide resolved
The default for a configuration item is optional; but the type is (via
an alias) apiextensionsv1.JSON, which is a struct. The zero value
serialises to `null`, which makes the Pulumi YAML engine balk.

Making this pointer typed means if it's absent, it'll be left out of the
serialisation, and Pulumi YAML won't disagree with it.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
At present the controller will notice changes to a Program object when
it reruns a Stack that refers to that object, either because it failed
the previous time, or because it requeued it on a schedule.

This adds an index keeping track of which Stacks reference which
Programs, and a watch that will requeue all the Stacks referring to a
Program when that program changes.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
A Stack can refer to a Flux source by (arbitrary) API version, kind, and
name. This gives forward-compatibility with new and third-party sources
-- but it makes it a bit trickier to detect when they have changed,
because the kinds to watch aren't known until they're seen by the
controller.

The scheme to do so here is:

 1. index the Stack against the type {group, version, kind} and name of
 the source they reference. This lets us look up the referencing stacks,
 when we see a source has been updated.

 2. whenever a source is successfully retrieved (during Stack
 reconciliation), ensure that its kind is being watched;

 3. the watchers installed in 2.) use the index in 1.) to look up the
 stacks using a source by type and name; then enqueue any such stacks to
 be reconciled.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
When a flux Source is missing, we can now wait for the watch to fire
when it appears, rather than retrying. The same is true when the source
is marked as unready.

Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
Signed-off-by: Michael Bridgen <mbridgen@pulumi.com>
@squaremo squaremo merged commit 3974c96 into master Oct 25, 2022
@squaremo squaremo deleted the watch-sources branch October 25, 2022 14:10
@squaremo
Copy link
Contributor Author

Thank you @roothorp and @lblackstone for looking over this ⭐

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.

Trigger Stack runs when a source is updated
2 participants