Change:
/kind bug What happened: Current context was set to cluster1. Ran and got back information about cluster1 instead. What you expected to happen: I expected the output to be the cluster2 information How to reproduce it (as minimally and precisely as possible): Have two contexts in your kube config, A and B Run to set A as current context Run Anything else we need to know?: I'd like to help contribute, so if this is an easy fix, someone point me in the right direction and I'll try to get it done. Environment: Kubernetes version (use ): 1.10.2 OS (e.g. from /etc/os-release): MacOS 10.11.6 Install tools: kubectl was installed via brew
Reiterating the mentions to trigger a notification: <detailsIn response to : 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
/assign Filed

Discussion:
streams, _, buf, _ := genericclioptions.NewTestIOStreams() cmd := NewCmdConfig(cmdutil.NewFactory(genericclioptions.NewTestConfigFlags()), clientcmd.NewDefaultPathOptions(), streams) <ins> // "context" is a global flag, inherited from base kubectl command in the real world cmd.PersistentFlags().String("context", "", "The name of the kubeconfig context to use") </ins> cmd.SetArgs(argsToUse) cmd.Execute() <del> // outBytes, _ := ioutil.ReadFile(fakeKubeFile.Name()) </del> config := clientcmd.GetConfigFromFileOrDie(fakeKubeFile.Name()) return buf.String(), *config }

Minify       bool RawByteData  bool <ins> Context      string </ins> OutputFormat string genericclioptions.IOStreams

return err } o.PrintObject = printer.PrintObj <ins> o.Context = cmdutil.GetFlagString(cmd, "context") </ins> return nil }

} if o.Minify { <ins> if len(o.Context) > 0 { config.CurrentContext = o.Context } </ins> if err := clientcmdapi.MinifyConfig(config); err != nil { return err }

"my-cluster": {Server: "https://192.168.0.1:3434"}, }, Contexts: map[string]*clientcmdapi.Context{ <del> "minikube":  {AuthInfo: "minikube", Cluster: "minikube"}, "my-cluser": {AuthInfo: "mu-cluster", Cluster: "my-cluster"}, </del> <ins> "minikube":   {AuthInfo: "minikube", Cluster: "minikube"}, "my-cluster": {AuthInfo: "mu-cluster", Cluster: "my-cluster"}, </ins> }, CurrentContext: "minikube", AuthInfos: map[string]*clientcmdapi.AuthInfo{ <del> "minikube":  {Token: "minikube-token"}, "my-cluser": {Token: "minikube-token"}, </del> <ins> "minikube":   {Token: "minikube-token"}, "mu-cluster": {Token: "minikube-token"}, </ins> }, } test := viewClusterTest{ description: "Testing for kubectl config view", config:      conf, <del> flags:       []string{}, </del> expected: `apiVersion: v1 clusters: - cluster:

- context: cluster: my-cluster user: mu-cluster <del> name: my-cluser </del> <ins> name: my-cluster </ins> current-context: minikube kind: Config preferences: {}

- name: minikube user: token: minikube-token <del> - name: my-cluser </del> <ins> - name: mu-cluster </ins> user: <del> token: minikube-token` + "n"} </del> <ins> token: minikube-token` + "n", } </ins> test.run(t) } func TestViewClusterMinify(t *testing.T) {

"my-cluster": {Server: "https://192.168.0.1:3434"}, }, Contexts: map[string]*clientcmdapi.Context{ <del> "minikube":  {AuthInfo: "minikube", Cluster: "minikube"}, "my-cluser": {AuthInfo: "mu-cluster", Cluster: "my-cluster"}, </del> <ins> "minikube":   {AuthInfo: "minikube", Cluster: "minikube"}, "my-cluster": {AuthInfo: "mu-cluster", Cluster: "my-cluster"}, </ins> }, CurrentContext: "minikube", AuthInfos: map[string]*clientcmdapi.AuthInfo{ <del> "minikube":  {Token: "minikube-token"}, "my-cluser": {Token: "minikube-token"}, </del> <ins> "minikube":   {Token: "minikube-token"}, "mu-cluster": {Token: "minikube-token"}, </ins> }, } <del> test := viewClusterTest{ description: "Testing for kubectl config view --minify=true", config:      conf, flags:       []string{"--minify=true"}, expected: `apiVersion: v1 </del> <ins> testCases := []struct { description string config      clientcmdapi.Config flags       []string expected    string }{ { description: "Testing for kubectl config view --minify=true", config:      conf, flags:       []string{"--minify=true"}, expected: `apiVersion: v1 </ins> clusters: - cluster: server: https://192.168.99.100:8443

users: - name: minikube user: <del> token: minikube-token` + "n"} test.run(t) </del> <ins> token: minikube-token` + "n", }, { description: "Testing for kubectl config view --minify=true --context=my-cluster", config:      conf, flags:       []string{"--minify=true", "--context=my-cluster"}, expected: `apiVersion: v1 clusters: - cluster: server: https://192.168.0.1:3434 name: my-cluster contexts: - context: cluster: my-cluster user: mu-cluster name: my-cluster current-context: my-cluster kind: Config preferences: {} users: - name: mu-cluster user: token: minikube-token` + "n", }, } for _, test := range testCases { cmdTest := viewClusterTest{ description: test.description, config:      test.config, flags:       test.flags, expected:    test.expected, } cmdTest.run(t) } </ins> } func (test viewClusterTest) run(t *testing.T) {

pathOptions.EnvVar = "" streams, _, buf, _ := genericclioptions.NewTestIOStreams() cmd := NewCmdConfigView(cmdutil.NewFactory(genericclioptions.NewTestConfigFlags()), streams, pathOptions) <ins> // "context" is a global flag, inherited from base kubectl command in the real world cmd.Flags().String("context", "", "The name of the kubeconfig context to use") </ins> cmd.Flags().Parse(test.flags) if err := cmd.Execute(); err != nil { t.Fatalf("unexpected error executing command: %v,kubectl config view flags: %v", err, test.flags) }