-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
updated phase runner to enable custom arg validation #77400
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
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
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.
Is there any reason to do this? I am not a particular fan of imposing
cobra.MaximumNArgs(1)
in this way.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'm not sure I understand this.What I mean to accomplish here is if you did not set any Args in the phase, to just use the parent commands arg checker. right?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.
Also, I believe this is what @fabriziopandini wanted kubernetes/kubeadm#1375 (comment)
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 just took the
join
case, forinit
this would becobra.NoArgs
. This means that we need to test all the phases to check for CLI breakages (especially the init phases).The original proposal by @fabriziopandini (in kubernetes/kubeadm#1375) states:
I agree with this, except for the fact, that
init
s top level cmd should usecobra.NoArgs
too (which it does ATM).The way you do it gets the job done, but I distaste the implicit behavior of this. Without full test coverage for all possible phases it can can cause problems in the future.
What I think is a bit more appropriate with respect to the above concern is to make stuff explicit - don't inherit anything from the parent command, but explicitly add the positional args verifier per phase. This will make the things more verbose though and the patch larger in size.
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 understand @rosti point that implicit behavior is ... not explicit when you read the code
I considered three options
a) to apply by default the parent arg validation of parent phase to leaf phases (current implementation)
b) to apply a predefined default to all phases e.g. NoArgs
c) to not apply any default for leaf phases, but to set args validation only if requested
The option c) goes in the direction of being explicit, but in the end, you have to set args for all phases, and I don't like the idea to add more knobs to all the phases (we already have eeetooomuch flags)
I discarded b) because choosing a default is tricky (why NoArgs instead of something else?)
So I'm back again to a), the current implementation, that IMO makes sense because phases are pieces of the main command, and so it is very likely that the args value of the parent command will make sense for leaf phases as well. In practices:
That means that with this approach we are changing only 4 phases over 20/30 phases currently in place
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.
The 4 select phases have been updated to
NoArg
I will squash and push when you all give the word. (if you like it that is.)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.
Ok, let's go with inheriting then.
+1 for some of the control-plane join phases to use NoArgs.