From 3ae85812bdc74ba2fb2bd45c181eadcaa32985b8 Mon Sep 17 00:00:00 2001 From: Robert Bailey Date: Fri, 27 Feb 2015 18:29:28 -0800 Subject: [PATCH] Use the kubectl binary rather than the wrapper shell script in the kubectl e2e test. --- hack/ginkgo-e2e.sh | 2 ++ test/e2e/kubectl.go | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/hack/ginkgo-e2e.sh b/hack/ginkgo-e2e.sh index db14e8fb404..e92c5f73757 100755 --- a/hack/ginkgo-e2e.sh +++ b/hack/ginkgo-e2e.sh @@ -103,6 +103,8 @@ else auth_config=() fi +# Use the kubectl binary from the same directory as the e2e binary. +export PATH=$(dirname "${e2e}"):"${PATH}" "${e2e}" "${auth_config[@]:+${auth_config[@]}}" \ --host="https://${KUBE_MASTER_IP-}" \ --provider="${KUBERNETES_PROVIDER}" \ diff --git a/test/e2e/kubectl.go b/test/e2e/kubectl.go index 19b0995d691..72879119e64 100644 --- a/test/e2e/kubectl.go +++ b/test/e2e/kubectl.go @@ -40,7 +40,7 @@ const ( var _ = Describe("kubectl", func() { - updateDemoRoot := filepath.Join(root, "examples/update-demo") + updateDemoRoot := filepath.Join(testContext.repoRoot, "examples/update-demo") nautilusPath := filepath.Join(updateDemoRoot, "nautilus-rc.yaml") kittenPath := filepath.Join(updateDemoRoot, "kitten-rc.yaml") @@ -174,15 +174,22 @@ func getData(hostIP string) (*updateDemoData, error) { } func runKubectl(args ...string) string { - // TODO: use kubectl binary directly instead of shell wrapper - path := filepath.Join(root, "cluster/kubectl.sh") - cmdStr := path + " " + strings.Join(args, " ") - Logf("Running '%v'", cmdStr) - - cmd := exec.Command(path, args...) + defaultArgs := []string{"--auth-path=" + testContext.authConfig} + if testContext.certDir != "" { + defaultArgs = append(defaultArgs, + fmt.Sprintf("--certificate-authority=%s", filepath.Join(testContext.certDir, "ca.crt")), + fmt.Sprintf("--client-certificate=%s", filepath.Join(testContext.certDir, "kubecfg.crt")), + fmt.Sprintf("--client-key=%s", filepath.Join(testContext.certDir, "kubecfg.key"))) + } + kubectlArgs := append(defaultArgs, args...) + // TODO: Remove this once gcloud writes a proper entry in the kubeconfig file. + if testContext.provider == "gke" { + kubectlArgs = append(kubectlArgs, "--server="+testContext.host) + } + Logf("Running 'kubectl %v'", strings.Join(kubectlArgs, " ")) + cmd := exec.Command("kubectl", kubectlArgs...) var stdout, stderr bytes.Buffer - cmd.Stdout = &stdout - cmd.Stderr = &stderr + cmd.Stdout, cmd.Stderr = &stdout, &stderr if err := cmd.Run(); err != nil { Failf("Error running %v:\nCommand stdout:\n%v\nstderr:\n%v\n", cmd, cmd.Stdout, cmd.Stderr)