-
Notifications
You must be signed in to change notification settings - Fork 1.2k
✨ Add ContainsFinalizer helper to the controllerutil #922
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
Conversation
Hi @dmvolod. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@joelanford, @alexeldeib could you please to have a look at this changes. |
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.
Thanks! This is something I've meaning to get to 🙂
/ok-to-test
@@ -446,6 +446,18 @@ var _ = Describe("Controllerutil", func() { | |||
Expect(deploy.ObjectMeta.GetFinalizers()).To(Equal([]string{})) | |||
}) | |||
}) | |||
|
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.
Can you also add a test for ContainsFinalizerWithError
, similar to the ones in lines 413-423?
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.
@joelanford , thanks, fixed
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dmvolod, joelanford 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 |
|
||
// ContainsFinalizerWithError checks a metav1 object that the provided finalizer is present. | ||
// It returns an error if the provided object cannot provide an accessor. | ||
func ContainsFinalizerWithError(o runtime.Object, finalizer string) (bool, error) { |
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.
Why is this needed? All concrete api types, be they built-in or CRDs, have am emedded metav1.ObjectMeta
and thus fulfill the metav1.Object
interface. If you really end up writing generic code that acts on a runtime.Object
you can just assert it as metav1.Object
prior to trying to find out if it has the given finalizer.
The only type of runtime.Object
where this will not work is list types, but that makes sense as they do not implement the metav1.Object
interface. IMHO it would be better to tell ppl at compile time that this isn't possible for Lists rather than at runtime when meta.Accessor
errors.
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 asked for this to be added to align with the other existing *WithError
functions in this package.
I agree, though, that compile time type checking is better than runtime type assertions. #898 may help with this.
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.
#898 merged so maybe we should remove ContainsFinalizerWithError
again and update ContainsFinalizer
to take an controllerutil.Object
as first agument?
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.
@alvaroaleman , thanks, I will do. Do we need also delete other *WithError methods and replace with controllerutil.Object methods which are not handling errors?
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.
For now, please leave the existing code as it is. Removing the WithError
funcs that we already have is a breaking change, so we should do it in a dedicated PR to make sure it gets its own release note and only gets merged when we are ready to take breaking changes.
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.
Fixed
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.
Thank you!
/lgtm
…ntime#922 is already merged Signed-off-by: Xudong Liu <[email protected]>
…ntime#922 is already merged Signed-off-by: Xudong Liu <[email protected]>
This is ContainsFinalizer helper in the controllerutil package which checks that provided finalizer exists in the Object meta
Fixes #920