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
✨return a bool from AddFinalizer and RemoveFinalizer #1636
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This addition does seem useful. But the other way which I could think of it is this:
ConatinsFinalizer()
, which is a linear operation of complexity O(n).ContainsFinalizer
+Add/RemoveFinalizer
where there would be linear iteration twice. The complexity still remains linear. I am not sure if there would be much performance improvement by saving on one iteration, since updating the object is anyway a necessity.We could still return a signal in Add or Remove Finalizer saying it has been updated or not, but I think boolean may not be apt. Returning
false
inAddFinalizer
can also be interpreted by users that it has not been added to the object at all (though with proper docs we could explain that its just adding element to a list). We can instead maybe return an indication that it is already present.However, this would be a breaking change. Also, I think the finalizer library already implements this in a better way. Would the library helpers satisfy your use case?
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 for the fast response!
The finalizer library contains the primary issue I intend to solve: two linear iterations. For example, on lines 57 and 58 when a finalizer is added:
controller-runtime/pkg/finalizer/finalizer.go
Lines 57 to 58 in 4e7f0c9
and lines 60 and 72 when one is removed. It does provide a bool
res.Updated
indicating whether the object was updated, but the reason I propose it be added is to avoid the two linear iterations issue it contains.The functions are called
AddFinalizer
andRemoveFinalizer
so I think it is intuitive and logical to interpret a boolean return code as an indication of whether each did, in this invocation, what its name indicates it should.I would be ok with wrapping the boolean in a struct just to give it a name that the programmer must type. The library's struct has more than one field, making a structure more reasonable.
A string takes more work to match.
I propose naming the bool return value
finalizersUpdated
in the function signature to avoid misinterpretation. I updated the pull request with that solution. Thoughts?