Change:
<!-- Thanks for filing an issue! Before hitting the button, please answer these questions.--Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see ): No, this is a bug report. What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.): Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG REPORT <!-- If this is a BUG REPORT, please: Fill in as much of the template below as you can. If you leave out information, we can't help you as well. If this is a FEATURE REQUEST, please: Describe in detail the feature/behavior/change you'd like to see. In both cases, be ready for followup questions, and please respond in a timely manner. If we can't reproduce a bug or think a feature already exists, we might close your issue. If we're wrong, PLEASE feel free to reopen it and explain why. --Kubernetes version (use ): Environment: Cloud provider or hardware configuration: MacBook Pro Mid-2015 OS (e.g. from /etc/os-release): macOS Kernel (e.g. ): Install tools: Others: N/A What happened: When deleting the context that was my current context, I entered a state where I am seemingly unable to set my context. The shows none as the current: Also, when trying to take any actions that require a context the following error is presented: When viewing the full config () I can see that my selected context is still the one I deleted. What you expected to happen: I believe there are two expectations I had: should allow me to delete my current context, but not enter an inconsistent state in the process -or- should either provide a warning or disallow removing your current context How to reproduce it (as minimally and precisely as possible): I believe that you just need a configuration with multiple contexts. I had three before deleting the context that has me unable to set a new context. list all contexts to find your current context () delete your current context list your current contexts again, and you'll see no contexts are created try to set your context with one of the ones that exist () listing your contexts again will show none being set Anything else we need to know: 3 contexts were configured before starting to delete one 2 of them were GKE clusters, automatically set up by the binary 1 is a context set up by the context I deleted was one of the contexts The issue was resolved by manually setting my context by editing .
I think this is the confusion of doesn't switch contexts, it lets you set fields on a context. is what switches contexts.
It's technically valid to have no current context, but I agree a warning message like "warning: this removed your active context, use to select a different one" would go a long way.
SGTM.

Discussion:
cmd.AddCommand(NewCmdConfigGetContexts(out, pathOptions)) cmd.AddCommand(NewCmdConfigGetClusters(out, pathOptions)) cmd.AddCommand(NewCmdConfigDeleteCluster(out, pathOptions)) <del> cmd.AddCommand(NewCmdConfigDeleteContext(out, pathOptions)) </del> <ins> cmd.AddCommand(NewCmdConfigDeleteContext(out, errOut, pathOptions)) </ins> return cmd }

kubectl config delete-context minikube`) ) <del> func NewCmdConfigDeleteContext(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command { </del> <ins> func NewCmdConfigDeleteContext(out, errOut io.Writer, configAccess clientcmd.ConfigAccess) *cobra.Command { </ins> cmd := &cobra.Command{ Use:     "delete-context NAME", Short:   i18n.T("Delete the specified context from the kubeconfig"), Long:    "Delete the specified context from the kubeconfig", Example: delete_context_example, Run: func(cmd *cobra.Command, args []string) { <del> err := runDeleteContext(out, configAccess, cmd) </del> <ins> err := runDeleteContext(out, errOut, configAccess, cmd) </ins> cmdutil.CheckErr(err) }, }

return cmd } <del> func runDeleteContext(out io.Writer, configAccess clientcmd.ConfigAccess, cmd *cobra.Command) error { </del> <ins> func runDeleteContext(out, errOut io.Writer, configAccess clientcmd.ConfigAccess, cmd *cobra.Command) error { </ins> config, err := configAccess.GetStartingConfig() if err != nil { return err

return fmt.Errorf("cannot delete context %s, not in %s", name, configFile) } <ins> if config.CurrentContext == name { fmt.Fprint(errOut, "warning: this removed your active context, use "kubectl config use-context" to select a different onen") } </ins> delete(config.Contexts, name) if err := clientcmd.ModifyConfig(configAccess, *config, true); err != nil {

pathOptions.EnvVar = "" buf := bytes.NewBuffer([]byte{}) <del> cmd := NewCmdConfigDeleteContext(buf, pathOptions) </del> <ins> errBuf := bytes.NewBuffer([]byte{}) cmd := NewCmdConfigDeleteContext(buf, errBuf, pathOptions) </ins> cmd.SetArgs([]string{test.contextToDelete}) if err := cmd.Execute(); err != nil { t.Fatalf("unexpected error executing command: %v", err)