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

ImagePolicy: Add predicates to filter events #334

Merged
merged 1 commit into from
Jan 10, 2023

Conversation

darkowlzz
Copy link
Contributor

ImagePolicy watcher adds every change to its own kind in the work queue which results in unnecessary multiple reconciliations.
Add a predicate to allow own kind events only on generation change. Other reconcilers in other repositories also use such predicates for the same purpose.

NOTE: In the current implementation of ImagePolicy reconciler, there's no logging due to which it's not apparent how many times it reconciled in the background. With the refactor in #311, every ImagePolicy reconciliation logs, which made multiple reconciliations more visible.
For example, creating a new ImagePolicy resulted in:

{"level":"info","ts":"2023-01-03T23:11:46.763+0530","msg":"Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to 5.0.3","controller":"imagepolicy","controllerGroup":"image.toolkit.fluxcd.io","controllerKind":"ImagePolicy","ImagePolicy":{"name":"podinfo","namespace":"default"},"namespace":"default","name":"podinfo","reconcileID":"cf5bd588-32a2-44ab-8027-6185e3d91775"}
{"level":"info","ts":"2023-01-03T23:11:46.770+0530","msg":"Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to 5.0.3","controller":"imagepolicy","controllerGroup":"image.toolkit.fluxcd.io","controllerKind":"ImagePolicy","ImagePolicy":{"name":"podinfo","namespace":"default"},"namespace":"default","name":"podinfo","reconcileID":"80729b49-a66d-482a-8d2e-9bbd2fc6bcf0"}
{"level":"info","ts":"2023-01-03T23:11:47.514+0530","msg":"Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to 5.0.3","controller":"imagepolicy","controllerGroup":"image.toolkit.fluxcd.io","controllerKind":"ImagePolicy","ImagePolicy":{"name":"podinfo","namespace":"default"},"namespace":"default","name":"podinfo","reconcileID":"6046cb8e-8ad6-4a89-82b8-1165ff3c6b85"}

With the new predicate:

{"level":"info","ts":"2023-01-04T00:02:40.199+0530","msg":"Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to 5.0.3","controller":"imagepolicy","controllerGroup":"image.toolkit.fluxcd.io","controllerKind":"ImagePolicy","ImagePolicy":{"name":"podinfo","namespace":"default"},"namespace":"default","name":"podinfo","reconcileID":"f0fcefe4-2361-4216-a099-eee751b525e8"}

Fixing it separately in the main branch to keep the number of specific changes in the refactor branch low.

ImagePolicy watcher adds every change to its own kind
in the work queue which results in unnecessary multiple
reconciliations.
Add a predicate to allow own kind events only on
generation change.

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

@relu relu left a comment

Choose a reason for hiding this comment

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

Great find, @darkowlzz! 💯

@@ -260,7 +262,7 @@ func (r *ImagePolicyReconciler) SetupWithManager(mgr ctrl.Manager, opts ImagePol
}

return ctrl.NewControllerManagedBy(mgr).
For(&imagev1.ImagePolicy{}).
For(&imagev1.ImagePolicy{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Copy link
Member

Choose a reason for hiding this comment

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

This is just an observation and is out of scope, but I'm wondering if we should support the reconcile request annotation for ImagePolicy in which case we'd also need to add the ReconcileRequestedPredicate in here. I think ImagePolicy is the only CR we don't support reconciliation requests for at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to ImagePolicy, Notification-controller Alerts also watch Providers but it supports reconcile request annotation. Based on that, we can either add the same here or maybe remove it from Alert.
There may be some historic reason behind it that I'm unaware of.

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.

3 participants