Change:
Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG REPORT Kubernetes version (use ): 1.5.3 Environment: Cloud provider or hardware configuration: minikube 0.17.1 How to reproduce it (as minimally and precisely as possible): config Note that there's only one context. the property of a non-existent context config Note that a context named foo was created just because I tried to unset a property. What you expected to happen: should give an informative message saying that context doesn't exist. Anything else we need to know: This is probably low-hanging fruit.
/sig cli
/assign i will take a look for this
GitHub didn't allow me to assign the following users: a, look, for, this, i, will, take. Note that only can be assigned. <detailsIn response to : /assign i will take a look for this Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
i can reproduce this, this is a bug, have open PR fix this. thanks
/kind bug

Discussion:
needToSetNewMapValue := currMapValue.Kind() == reflect.Invalid if needToSetNewMapValue { <ins> if unset { return fmt.Errorf("current map key `%v` is invalid", mapKey.Interface()) } </ins> currMapValue = reflect.New(mapValueType.Elem()).Elem().Addr() actualCurrValue.SetMapIndex(mapKey, currMapValue) }

Short: i18n.T("Unsets an individual value in a kubeconfig file"), Long:  unset_long, Run: func(cmd *cobra.Command, args []string) { <del> cmdutil.CheckErr(options.complete(cmd)) cmdutil.CheckErr(options.run()) fmt.Fprintf(out, "Property %q unset.n", options.propertyName) </del> <ins> cmdutil.CheckErr(options.complete(cmd, args)) cmdutil.CheckErr(options.run(out)) </ins> }, } return cmd } <del> func (o unsetOptions) run() error { </del> <ins> func (o unsetOptions) run(out io.Writer) error { </ins> err := o.validate() if err != nil { return err

return err } <del> return clientcmd.ModifyConfig(o.configAccess, *config, false) </del> <ins> if err := clientcmd.ModifyConfig(o.configAccess, *config, false); err != nil { return err } if _, err := fmt.Fprintf(out, "Property %q unset.n", o.propertyName); err != nil { return err } return nil </ins> } <del> func (o *unsetOptions) complete(cmd *cobra.Command) error { endingArgs := cmd.Flags().Args() if len(endingArgs) != 1 { return helpErrorf(cmd, "Unexpected args: %v", endingArgs) </del> <ins> func (o *unsetOptions) complete(cmd *cobra.Command, args []string) error { if len(args) != 1 { return helpErrorf(cmd, "Unexpected args: %v", args) </ins> } <del> o.propertyName = endingArgs[0] </del> <ins> o.propertyName = args[0] </ins> return nil }

type unsetConfigTest struct { description string <del> config      clientcmdapi.Config //initiate kubectl config args        []string            //kubectl config unset args expected    string              //expect out </del> <ins> config      clientcmdapi.Config args        []string expected    string expectedErr string </ins> } func TestUnsetConfigString(t *testing.T) {

test.run(t) } <ins> func TestUnsetUnexistConfig(t *testing.T) { conf := clientcmdapi.Config{ Kind:       "Config", APIVersion: "v1", Clusters: map[string]*clientcmdapi.Cluster{ "minikube":   {Server: "https://192.168.99.100:8443"}, "my-cluster": {Server: "https://192.168.0.1:3434"}, }, Contexts: map[string]*clientcmdapi.Context{ "minikube":   {AuthInfo: "minikube", Cluster: "minikube"}, "my-cluster": {AuthInfo: "mu-cluster", Cluster: "my-cluster"}, }, CurrentContext: "minikube", } test := unsetConfigTest{ description: "Testing for kubectl config unset a unexist map key", config:      conf, args:        []string{"contexts.foo.namespace"}, expectedErr: "current map key `foo` is invalid", } test.run(t) } </ins> func (test unsetConfigTest) run(t *testing.T) { fakeKubeFile, err := ioutil.TempFile(os.TempDir(), "") if err != nil {

pathOptions.EnvVar = "" buf := bytes.NewBuffer([]byte{}) cmd := NewCmdConfigUnset(buf, pathOptions) <del> cmd.SetArgs(test.args) if err := cmd.Execute(); err != nil { t.Fatalf("unexpected error executing command: %v,kubectl unset args: %v", err, test.args) </del> <ins> opts := &unsetOptions{configAccess: pathOptions} err = opts.complete(cmd, test.args) if err == nil { err = opts.run(buf) </ins> } config, err := clientcmd.LoadFromFile(fakeKubeFile.Name()) if err != nil { t.Fatalf("unexpected error loading kubeconfig file: %v", err) } <ins> if err != nil && err.Error() != test.expectedErr { t.Fatalf("expected error:n %vnbut got error:n%v", test.expectedErr, err) } </ins> if len(test.expected) != 0 { if buf.String() != test.expected { t.Errorf("Failed in :%qn expected %vn but got %v", test.description, test.expected, buf.String())