-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
Conversation
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 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-bot ok to test Typo in title. |
kubeclt config rename-context
4317b81
to
840a4be
Compare
s/kubeclt/kubectl |
kubeclt config rename-context
kubectl config rename-context
/release-note-none |
kubectl config rename-context
kubectl config rename-context
kubectl config rename-context
kubectl config rename-context
Please run to fix EDIT: nvm. It seems the bot didn't update the comment above. |
@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)) |
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.
According to https://github.com/kubernetes/community/blob/master/contributors/devel/kubectl-conventions.md#command-implementation-conventions, you should capitalize:
- Complete
- Validate
- Run
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.
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) |
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.
nit: use cannot rename the context %q, it's not in %s
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.
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) |
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.
nit: use cannot rename the context %q, the context %q already exists in %s
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.
Done.
"fmt" | ||
"io" | ||
|
||
"github.com/spf13/cobra" |
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.
Add a new line after this line.
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.
Done.
expectedOut string //expected out | ||
} | ||
|
||
func TestRenameContext(t *testing.T) { |
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.
Can you add more tests to make sure it can handle error cases.
This is a new command and it deserve a release note. |
@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()) |
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.
"Failed ..."
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.
Done.
|
||
CONTEXT_NAME is the context name that you wish change. | ||
|
||
NEW_NAME is the new name you wish to set.`) |
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.
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.
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.
Done.
Overall looks good, comments are minor. @deads2k what do you think? |
Enables renaming of a context via `kubectl` Fix kubernetes#45131
@arthur0: The following test(s) failed:
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. |
@k8s-bot pull-kubernetes-unit test this |
/lgtm |
/assign @pwittrock |
/approve |
[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 |
Automatic merge from submit-queue (batch tested with PRs 46489, 46281, 46463, 46114, 43946) |
Thank you @arthur0 for adding this! 👍 |
Add
kubectl config rename-context
This command allows renaming a context, instead of editing manually in .kubeconfig
Fix #45131