diff --git a/test/framework/exec/kubectl.go b/test/framework/exec/kubectl.go index 9fd54de36045..0b3069348cd4 100644 --- a/test/framework/exec/kubectl.go +++ b/test/framework/exec/kubectl.go @@ -20,6 +20,7 @@ import ( "bytes" "context" "fmt" + "os" ) // KubectlApply shells out to kubectl apply. @@ -29,7 +30,7 @@ func KubectlApply(ctx context.Context, kubeconfigPath string, resources []byte, aargs := append([]string{"apply", "--kubeconfig", kubeconfigPath, "-f", "-"}, args...) rbytes := bytes.NewReader(resources) applyCmd := NewCommand( - WithCommand("kubectl"), + WithCommand(kubectlPath()), WithArgs(aargs...), WithStdin(rbytes), ) @@ -46,7 +47,7 @@ func KubectlApply(ctx context.Context, kubeconfigPath string, resources []byte, func KubectlWait(ctx context.Context, kubeconfigPath string, args ...string) error { wargs := append([]string{"wait", "--kubeconfig", kubeconfigPath}, args...) wait := NewCommand( - WithCommand("kubectl"), + WithCommand(kubectlPath()), WithArgs(wargs...), ) _, stderr, err := wait.Run(ctx) @@ -56,3 +57,10 @@ func KubectlWait(ctx context.Context, kubeconfigPath string, args ...string) err } return nil } + +func kubectlPath() string { + if kubectlPath, ok := os.LookupEnv("CAPI_KUBECTL_PATH"); ok { + return kubectlPath + } + return "kubectl" +}