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

Add kubectl config rename-context #46114

Merged
merged 1 commit into from
May 30, 2017

Conversation

arthur0
Copy link

@arthur0 arthur0 commented May 19, 2017

Add kubectl config rename-context

This command allows renaming a context, instead of editing manually in .kubeconfig

Fix #45131

Add `kubectl config rename-context`

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 19, 2017
@k8s-ci-robot
Copy link
Contributor

Hi @arthur0. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with @k8s-bot ok to test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 19, 2017
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-label-needed labels May 19, 2017
@mengqiy
Copy link
Member

mengqiy commented May 20, 2017

@k8s-bot ok to test

Typo in title.

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 20, 2017
@arthur0 arthur0 changed the title Add kubeclt config rename-context Add kubeclt config rename-context May 22, 2017
@arthur0 arthur0 force-pushed the rename_context branch 3 times, most recently from 4317b81 to 840a4be Compare May 22, 2017 17:12
@mengqiy
Copy link
Member

mengqiy commented May 22, 2017

s/kubeclt/kubectl

@arthur0 arthur0 changed the title Add kubeclt config rename-context Add kubectl config rename-context May 22, 2017
@arthur0
Copy link
Author

arthur0 commented May 22, 2017

/release-note-none

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. and removed release-note-label-needed labels May 22, 2017
@arthur0 arthur0 changed the title Add kubectl config rename-context [WIP] Add kubectl config rename-context May 22, 2017
@arthur0 arthur0 changed the title [WIP] Add kubectl config rename-context Add kubectl config rename-context May 23, 2017
@mengqiy
Copy link
Member

mengqiy commented May 23, 2017

Please run to fix verify:
hack/update-boilerplate.sh
hack/update-generated-docs.sh
hack/update-gofmt.sh

EDIT: nvm. It seems the bot didn't update the comment above.

@mengqiy
Copy link
Member

mengqiy commented May 23, 2017

@k8s-bot pull-kubernetes-e2e-gce-etcd3 test this

Long: templates.LongDesc(renameContextLong),
Example: templates.Examples(renameContextExample),
Run: func(cmd *cobra.Command, args []string) {
cmdutil.CheckErr(options.complete(cmd))
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Done.


context, exists := config.Contexts[o.contextName]
if !exists {
return fmt.Errorf("cannot rename the context %s, it's not in %s", o.contextName, configFile)
Copy link
Member

Choose a reason for hiding this comment

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

nit: use cannot rename the context %q, it's not in %s

Copy link
Author

Choose a reason for hiding this comment

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

Done.


_, newExists := config.Contexts[o.newName]
if newExists {
return fmt.Errorf("cannot rename the context %s, the context %s already exists in %s", o.contextName, o.newName, configFile)
Copy link
Member

Choose a reason for hiding this comment

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

nit: use cannot rename the context %q, the context %q already exists in %s

Copy link
Author

Choose a reason for hiding this comment

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

Done.

"fmt"
"io"

"github.com/spf13/cobra"
Copy link
Member

Choose a reason for hiding this comment

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

Add a new line after this line.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

expectedOut string //expected out
}

func TestRenameContext(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add more tests to make sure it can handle error cases.

@mengqiy
Copy link
Member

mengqiy commented May 23, 2017

This is a new command and it deserve a release note.
/release-note

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels May 23, 2017
@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/old-docs size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 26, 2017
@k8s-github-robot k8s-github-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 26, 2017
@fabianofranz
Copy link
Contributor

@arthur0 Thanks for the PR! Please add a release note to the original PR comment following these instructions.


if len(test.expectedOut) != 0 {
if buf.String() != test.expectedOut {
t.Errorf("Failded in:%q\n expected out %v\n but got %v", test.description, test.expectedOut, buf.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

"Failed ..."

Copy link
Author

Choose a reason for hiding this comment

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

Done.


CONTEXT_NAME is the context name that you wish change.

NEW_NAME is the new name you wish to set.`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a note here in the long desc mentioning something like "in case the context being renamed is the one in use, the 'current-context' field will also be updated to point to the new name". Good job handling that btw.

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@fabianofranz
Copy link
Contributor

Overall looks good, comments are minor. @deads2k what do you think?

Enables renaming of a context via `kubectl`

Fix kubernetes#45131
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented May 26, 2017

@arthur0: The following test(s) failed:

Test name Commit Details Rerun command
Jenkins verification f5da7f2 link @k8s-bot verify test this

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.

@mengqiy
Copy link
Member

mengqiy commented May 26, 2017

@k8s-bot pull-kubernetes-unit test this

@deads2k
Copy link
Contributor

deads2k commented May 30, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 30, 2017
@arthur0
Copy link
Author

arthur0 commented May 30, 2017

/assign @pwittrock

@pwittrock
Copy link
Member

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: arthur0, deads2k, pwittrock

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-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 30, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 46489, 46281, 46463, 46114, 43946)

@k8s-github-robot k8s-github-robot merged commit 1889d65 into kubernetes:master May 30, 2017
@arthur0 arthur0 deleted the rename_context branch May 30, 2017 20:28
@hostirosti
Copy link

Thank you @arthur0 for adding this! 👍

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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants