Skip to content
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

Merged
merged 1 commit into from
Jan 7, 2018

Conversation

dixudx
Copy link
Member

@dixudx dixudx commented Dec 4, 2017

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:

Forbid unnamed contexts in kubeconfigs.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 4, 2017
@dixudx dixudx force-pushed the forbid_unnamed_context branch from 0f6e4b7 to 4513f43 Compare December 5, 2017 02:09
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 5, 2017
@@ -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)
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. Updated. PTAL.

@sttts
Copy link
Contributor

sttts commented Dec 12, 2017

/assign liggitt

@@ -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")
Copy link
Member

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 {
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

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"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad.

@dixudx dixudx force-pushed the forbid_unnamed_context branch 2 times, most recently from ea287ac to 20da5a0 Compare December 13, 2017 02:50
@fabianofranz
Copy link
Contributor

/unassign

@dixudx dixudx force-pushed the forbid_unnamed_context branch from af00893 to 792a229 Compare January 7, 2018 02:52
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 7, 2018
@dixudx
Copy link
Member Author

dixudx commented Jan 7, 2018

ping @liggitt for another look. Thanks.

@liggitt
Copy link
Member

liggitt commented Jan 7, 2018

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 7, 2018
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 7, 2018
@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

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.

@k8s-github-robot k8s-github-robot merged commit a2bce0d into kubernetes:master Jan 7, 2018
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jan 7, 2018

@dixudx: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-e2e-gce 792a229 link /test pull-kubernetes-e2e-gce

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.

@dixudx dixudx deleted the forbid_unnamed_context branch January 8, 2018 01:32
@sttts
Copy link
Contributor

sttts commented Jan 8, 2018

Updated the release note. Ptal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubectl config view --minify=true fails for kubeconfig without current context
6 participants