From fdca7d6844bc93b412d8bc71303de965b56945e0 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 30 Jun 2021 20:41:11 +0000 Subject: [PATCH] support renaming binary to kubectl.exe and running as kubectl --- cmd/minikube/cmd/root.go | 1 + cmd/minikube/main.go | 2 ++ test/integration/functional_test.go | 6 +++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/root.go b/cmd/minikube/cmd/root.go index 269b74752e..e85688d8a9 100644 --- a/cmd/minikube/cmd/root.go +++ b/cmd/minikube/cmd/root.go @@ -100,6 +100,7 @@ func Execute() { } _, callingCmd := filepath.Split(os.Args[0]) + callingCmd = strings.TrimSuffix(callingCmd, ".exe") if callingCmd == "kubectl" { // If the user is using the minikube binary as kubectl, allow them to specify the kubectl context without also specifying minikube profile diff --git a/cmd/minikube/main.go b/cmd/minikube/main.go index e29b9653ad..496ec6e9fd 100644 --- a/cmd/minikube/main.go +++ b/cmd/minikube/main.go @@ -28,6 +28,7 @@ import ( "path/filepath" "regexp" "strconv" + "strings" "github.com/spf13/pflag" "k8s.io/klog/v2" @@ -67,6 +68,7 @@ func main() { // Don't parse flags when running as kubectl _, callingCmd := filepath.Split(os.Args[0]) + callingCmd = strings.TrimSuffix(callingCmd, ".exe") parse := callingCmd != "kubectl" setFlags(parse) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index b6ffd91d65..c161ed34ab 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -645,7 +645,11 @@ func validateMinikubeKubectl(ctx context.Context, t *testing.T, profile string) func validateMinikubeKubectlDirectCall(ctx context.Context, t *testing.T, profile string) { defer PostMortemLogs(t, profile) dir := filepath.Dir(Target()) - dstfn := filepath.Join(dir, "kubectl") + newName := "kubectl" + if runtime.GOOS == "windows" { + newName += ".exe" + } + dstfn := filepath.Join(dir, newName) err := os.Link(Target(), dstfn) if err != nil {