initial attempt to account for profile in directly kubectl case

pull/9578/head
Sharif Elgamal 2020-10-28 12:16:02 -07:00
parent d4d645bbac
commit 4a1c9583bd
3 changed files with 15 additions and 2 deletions

View File

@ -43,6 +43,7 @@ minikube kubectl -- get pods --namespace kube-system`,
co := mustload.Healthy(ClusterFlagValue())
version := co.Config.KubernetesConfig.KubernetesVersion
fmt.Printf("args=%+v\n", args)
c, err := KubectlCommand(version, args...)
if err != nil {
out.ErrLn("Error caching kubectl: %v", err)

View File

@ -71,7 +71,19 @@ 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)
}
}
os.Args = append([]string{RootCmd.Use, callingCmd, profile, "--"}, os.Args[1:]...)
fmt.Printf("%+v\n", os.Args)
}
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)