Skip to content

Commit

Permalink
support renaming binary to kubectl.exe and running as kubectl
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Jun 30, 2021
1 parent 6e3aba5 commit fdca7d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/minikube/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/minikube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"

"github.com/spf13/pflag"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fdca7d6

Please sign in to comment.