-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 predicate for Generation change on update event #553
✨ Add predicate for Generation change on update event #553
Conversation
/assign @droot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, have a couple of minor comments.
pkg/predicate/predicate.go
Outdated
@@ -116,3 +116,32 @@ func (ResourceVersionChangedPredicate) Update(e event.UpdateEvent) bool { | |||
} | |||
return true | |||
} | |||
|
|||
// GenerationChangedPredicate implements a default update predicate function on generation change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be good to add the details that you specified in the PR description especially mentioning status
sub-resource. That sort of explains when
this predicate is useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also like to see an update to the examples to show how to use the predicate? WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean showing how to use one of the pre-defined predicates as an argument to the controller's Watch()?
I guess I could add that since I don't see it in any of the other examples:
https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/controller#ex-Controller
There's also an existing example in the predicate godoc, outlining how to define a new predicate.
Interestingly enough it's using generation change as the example.
https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/predicate/example_test.go#L27-L33
https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/predicate#ex-Funcs
I could update that to be more complete like the one written here. Or leave that as it is if it's meant to be just a short example.
@droot Let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to keep that example as-is.
In addition to a "why", I think this needs a "caveats" section -- like "this means you won't self-correct when someone else wipes your status".
f67d7fa
to
bdc1712
Compare
Updated the godocs for @shawn-hurley Based on the comments above I haven't updated the existing example. Let me know if you think we still need another example. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DirectXMan12, hasbro17 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Adds a
GenerationChangedPredicate
predicate similar to theResourceVersionChangedPredicate
that will filter out update events if an object'smetadata.generation
is unchanged.This predicate is needed since the CRD status subresource is more commonly enabled now which allows users to filter out updates that have no spec changes.
Since this is a common ask, this predicate is better suited as a helper in the predicate library rather than having users write it themselves or being somewhere downstream in the operator-sdk.
Side note: For CRD objects the Generation increment is skipped on metatdata updates as expected. But this behavior isn't consistent for other APIs e.g Deployments where annotation updates will cause a Generation bump. kubernetes/kubernetes#67428 (comment)
I wasn't sure if this is worth pointing out in the comments though.