-
Notifications
You must be signed in to change notification settings - Fork 40k
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
forbid unnamed context #56769
forbid unnamed context #56769
Conversation
0f6e4b7
to
4513f43
Compare
@@ -167,6 +168,9 @@ func addConversionFuncs(scheme *runtime.Scheme) error { | |||
if err := s.Convert(&curr.Context, newContext, 0); err != nil { | |||
return err | |||
} | |||
if len(curr.Name) == 0 { | |||
return fmt.Errorf("you must specify a non-empty context name for %#v", curr) |
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.
non-empty context names are not allowed. "you" sounds strange here.
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.
Make sense. Updated. PTAL.
/assign liggitt |
4513f43
to
62e9f34
Compare
@@ -88,7 +88,7 @@ func (o *useContextOptions) complete(cmd *cobra.Command) error { | |||
|
|||
func (o useContextOptions) validate(config *clientcmdapi.Config) error { | |||
if len(o.contextName) == 0 { | |||
return errors.New("you must specify a current-context") | |||
return errors.New("non-empty context names are not allowed") |
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 message text is very confusing
@@ -167,6 +168,9 @@ func addConversionFuncs(scheme *runtime.Scheme) error { | |||
if err := s.Convert(&curr.Context, newContext, 0); err != nil { | |||
return err | |||
} | |||
if len(curr.Name) == 0 { |
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.
conversion isn't the right place to do validation like this... validate at point of use
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 such conversionFuncs
registered/initialized at init
, it is quite hard to do the validate at point of use. Will looks quite ugly if added IMO.
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.
Errors in conversion do not surface well. This data should not prevent conversion.
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.
@@ -167,6 +168,9 @@ func addConversionFuncs(scheme *runtime.Scheme) error { | |||
if err := s.Convert(&curr.Context, newContext, 0); err != nil { | |||
return err | |||
} | |||
if len(curr.Name) == 0 { | |||
return fmt.Errorf("non-empty context name for %#v is not allowed", curr) |
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 think this should be "empty context name is not allowed"
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.
my bad.
ea287ac
to
20da5a0
Compare
/unassign |
5cd0f90
to
af00893
Compare
af00893
to
792a229
Compare
ping @liggitt for another look. Thanks. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dixudx, liggitt Associated issue: #56747 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue (batch tested with PRs 57521, 56769). If you want to cherry-pick this change to another branch, please follow the instructions here. |
@dixudx: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
Updated the release note. Ptal. |
What this PR does / why we need it:
forbid unnamed contexts with validation
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #56747
Special notes for your reviewer:
/assign @sttts @fabianofranz
Release note: