diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 5cd9ae7975..63662dd2f9 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -71,7 +71,23 @@ func Execute() { _, callingCmd := filepath.Split(os.Args[0]) if callingCmd == "kubectl" { - os.Args = append([]string{RootCmd.Use, callingCmd}, os.Args[1:]...) + // If the user is using the minikube binary as kubectl, allow them to specify the kubectl context without also specifying minikube profile + profile := "" + for i, a := range os.Args { + if a == "--context" { + profile = fmt.Sprintf("--profile=%s", os.Args[i+1]) + break + } else if strings.HasPrefix(a, "--context=") { + context := strings.Split(a, "=")[1] + profile = fmt.Sprintf("--profile=%s", context) + break + } + } + if profile != "" { + os.Args = append([]string{RootCmd.Use, callingCmd, profile, "--"}, os.Args[1:]...) + } else { + os.Args = append([]string{RootCmd.Use, callingCmd, "--"}, os.Args[1:]...) + } } for _, c := range RootCmd.Commands() { c.Short = translate.T(c.Short) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 0a781bd596..16c2170e8a 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -328,7 +328,7 @@ func validateMinikubeKubectlDirectCall(ctx context.Context, t *testing.T, profil } defer os.Remove(dstfn) // clean up - kubectlArgs := []string{"get", "pods"} + kubectlArgs := []string{"--context", profile, "get", "pods"} rr, err := Run(t, exec.CommandContext(ctx, dstfn, kubectlArgs...)) if err != nil { t.Fatalf("failed to run kubectl directly. args %q: %v", rr.Command(), err)