Skip to content

Commit

Permalink
e2e: Support use customize kubectl
Browse files Browse the repository at this point in the history
Signed-off-by: zhanglei <[email protected]>
  • Loading branch information
scuzhanglei committed Aug 5, 2022
1 parent 0b368a4 commit 898c54d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test/framework/exec/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,21 @@ import (
"bytes"
"context"
"fmt"
"os"
)

// KubectlApply shells out to kubectl apply.
//
// TODO: Remove this usage of kubectl and replace with a function from apply.go using the controller-runtime client.
func KubectlApply(ctx context.Context, kubeconfigPath string, resources []byte, args ...string) error {
kubectlPath, ok := os.LookupEnv("CAPI_KUBECTL_PATH")
if !ok {
kubectlPath = "kubectl"
}
aargs := append([]string{"apply", "--kubeconfig", kubeconfigPath, "-f", "-"}, args...)
rbytes := bytes.NewReader(resources)
applyCmd := NewCommand(
WithCommand("kubectl"),
WithCommand(kubectlPath),
WithArgs(aargs...),
WithStdin(rbytes),
)
Expand All @@ -44,9 +49,13 @@ func KubectlApply(ctx context.Context, kubeconfigPath string, resources []byte,

// KubectlWait shells out to kubectl wait.
func KubectlWait(ctx context.Context, kubeconfigPath string, args ...string) error {
kubectlPath, ok := os.LookupEnv("CAPI_KUBECTL_PATH")
if !ok {
kubectlPath = "kubectl"
}
wargs := append([]string{"wait", "--kubeconfig", kubeconfigPath}, args...)
wait := NewCommand(
WithCommand("kubectl"),
WithCommand(kubectlPath),
WithArgs(wargs...),
)
_, stderr, err := wait.Run(ctx)
Expand Down

0 comments on commit 898c54d

Please sign in to comment.