Merge pull request #9578 from sharifelgamal/kc-direct

Fix minikube kubectl direct call test by allowing users to specify context
pull/9576/head^2
Sharif Elgamal 2020-10-28 17:36:55 -07:00 committed by GitHub
commit 73e27e4a2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -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)

View File

@ -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)