Merge pull request #9578 from sharifelgamal/kc-direct
Fix minikube kubectl direct call test by allowing users to specify contextpull/9576/head^2
commit
73e27e4a2c
|
@ -71,7 +71,23 @@ func Execute() {
|
||||||
_, callingCmd := filepath.Split(os.Args[0])
|
_, callingCmd := filepath.Split(os.Args[0])
|
||||||
|
|
||||||
if callingCmd == "kubectl" {
|
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() {
|
for _, c := range RootCmd.Commands() {
|
||||||
c.Short = translate.T(c.Short)
|
c.Short = translate.T(c.Short)
|
||||||
|
|
|
@ -328,7 +328,7 @@ func validateMinikubeKubectlDirectCall(ctx context.Context, t *testing.T, profil
|
||||||
}
|
}
|
||||||
defer os.Remove(dstfn) // clean up
|
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...))
|
rr, err := Run(t, exec.CommandContext(ctx, dstfn, kubectlArgs...))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to run kubectl directly. args %q: %v", rr.Command(), err)
|
t.Fatalf("failed to run kubectl directly. args %q: %v", rr.Command(), err)
|
||||||
|
|
Loading…
Reference in New Issue