-
Notifications
You must be signed in to change notification settings - Fork 40.1k
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
kubeadm: better error handling for unknown phases and commands #127096
kubeadm: better error handling for unknown phases and commands #127096
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: neolit123 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 |
/triage accepted |
Short: fmt.Sprintf("Use this command to invoke single phase of the %s workflow", cmd.Name()), | ||
Args: cobra.NoArgs, |
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 tells the cmd that anything after e.g. kubeadm init phase ...
is not an arg but a subcommand.
Short: fmt.Sprintf("Use this command to invoke single phase of the %s workflow", cmd.Name()), | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return errors.Errorf("%s\n\nphase name is required", e.Help(phaseCommandUse)) |
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.
RunE here just returns and error that has the constructed Help() screen.
it means that one should be calling the parent phase command without a subcommand.
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.
please double check my understanding in case this might break some odd behavior that we have.
/hold for review
A similar case shows a different message, but both looks OK.
|
that's because these is a custom cmdutil.SubCmdRun() function. it's supposed to also print the help screen (-h) but it doesn't work. i can try adding a second commit to this PR that aligns all errors to do the same. i might drop printing the help screen on unknown commands as that seems hacky. |
/lgtm
Not have to. |
LGTM label has been added. Git tree hash: 357739cd7664c5d2f5f3f4e399fdf55b69fcb99e
|
LGTM |
/hold |
851a70f
to
5749564
Compare
5749564
to
1529e5a
Compare
If an unknown command or a phase is called consistently return the same error. If a command that has subcommands is called return an error. To achieve the above add a new util function RequireSubcommand() that sets NoArgs and RunE for regular commands or a "phase" command. Remove MacroCommandLongDescription and just return an error that a subcommand is required from the phase runner. Fix minor comments capitalization. Perform other minor fixes in util/error.go.
1529e5a
to
b497d28
Compare
|
||
// MacroCommandLongDescription provide a standard description for "macro" commands | ||
MacroCommandLongDescription = LongDesc(` | ||
This command is not meant to be run on its own. See list of available subcommands. |
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.
@SataQiu re: 'upgrade apply' phases, your PR can hopefully merge first and will make this PR to remove also the MacroCommandLongDescription from new phases.
/hold
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.
@SataQiu re: 'upgrade apply' phases, your PR can hopefully merge first and will make this PR to remove also the MacroCommandLongDescription from new phases.
/hold
seems no longer needed. the macro description is removed without conflicts.
/retest |
/retest |
looking for review/LGTM |
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.
/lgtm
LGTM label has been added. Git tree hash: 982c7b55a0914e4346674dbf8893296c31acb5bf
|
/hold cancel |
What type of PR is this?
/kind feature
What this PR does / why we need it:
If an unknown command or a phase is called consistently
return the same error.
If a command that has subcommands is called
return an error.
To achieve the above add a new util function
RequireSubcommand() that sets NoArgs and RunE for
regular commands or a "phase" command.
Remove MacroCommandLongDescription and just return an
error that a subcommand is required from the phase runner.
Fix minor comments capitalization.
Perform other minor fixes in util/error.go.
Which issue(s) this PR fixes:
xref kubernetes/kubeadm#3093 (comment)
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: