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

Add predicates for GitRepo and ImagePolicy watches #639

Merged
merged 1 commit into from
Feb 28, 2024
Merged

Conversation

darkowlzz
Copy link
Contributor

While working on the refactoring the controller, I noticed that it was getting triggered more than expected. This change is similar to a corresponding change in image-reflector-controller ImagePolicyReconciler, refer fluxcd/image-reflector-controller#334, to reduce unnecessary reconciliations. Adding this to the main branch separately from the refactor to reduce introducing new behavior in the refactor branch.

ImageUpdateAutomationReconciler watches GitRepository and ImagePolicy kinds for every event. This leads to unnecessary extra reconciliations at times. For example when the controller starts with existing resources, the same ImageUpdateAutomation object gets reconciled at least twice, once due to the watch on ImageUpdateAutomation at startup and again due to the watches on GitRepository and ImagePolicy for create event, as they get registered in the cache.

Add predicates to filter the ImagePolicy watch to only allow events for latest image update, and GitRepository watch to only allow events for change in the source configuration.

For example, previously when the controller started with existing resources, following multiple reconciliations could be seen:

2024-02-27T02:00:08.759+0530    INFO    no changes made in working directory; no commit {"controller": "imageupdateautomation", "controllerGroup": "image.toolkit.fluxcd.io", "controllerKind": "ImageUpdateAutomation", "ImageUpdateAutomation": {"name":"test-update-auto","namespace":"default"}, "namespace": "default", "name": "test-update-auto", "reconcileID": "84600cf1-8461-4636-96c7-b0f5fe464506"}
2024-02-27T02:00:08.832+0530    INFO    no changes made in working directory; no commit {"controller": "imageupdateautomation", "controllerGroup": "image.toolkit.fluxcd.io", "controllerKind": "ImageUpdateAutomation", "ImageUpdateAutomation": {"name":"test-update-auto","namespace":"default"}, "namespace": "default", "name": "test-update-auto", "reconcileID": "ff70cb0f-ef70-41d2-b036-3008fc5a26c4"}

With the new predicates:

2024-02-27T03:25:27.862+0530    INFO    no changes made in working directory; no commit {"controller": "imageupdateautomation", "controllerGroup": "image.toolkit.fluxcd.io", "controllerKind": "ImageUpdateAutomation", "ImageUpdateAutomation": {"name":"test-update-auto","namespace":"default"}, "namespace": "default", "name": "test-update-auto", "reconcileID": "86861ba9-5466-42a8-8ada-c0fb1b307f5e"}

Also adds a test to make sure that ImageUpdateAutomation continues to get triggered on updates to ImagePolicy and GitRepository.

ImageUpdateAutomationReconciler watches GitRepository and ImagePolicy
kinds for every event. This leads to unnecessary extra reconciliations
at times. For example when the controller starts with existing
resources, the same ImageUpdateAutomation object gets reconciled at
least twice, once due to the watch on ImageUpdateAutomation startup
and again due to the watches on GitRepository and ImagePolicy for create
event, as they get registered in the cache.

Add predicates to filter the ImagePolicy to only allow events for latest
image update, and GitRepository to only allow events for change in the
source configuration.

Signed-off-by: Sunny <[email protected]>
@darkowlzz darkowlzz added the enhancement New feature or request label Feb 26, 2024
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @darkowlzz 🥇

@darkowlzz darkowlzz merged commit 0b25ac9 into main Feb 28, 2024
8 checks passed
@darkowlzz darkowlzz deleted the watch-predicates branch February 28, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants