From d47d51d8ab3d83a473d2423a8195a119b0e07472 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Tue, 23 Jul 2019 23:52:45 -0700 Subject: [PATCH] Adding optional set kubecontext --- test/integration/addons_test.go | 6 ++++-- test/integration/cluster_dns_test.go | 6 +++--- test/integration/mount_test.go | 6 +++--- test/integration/pv_test.go | 2 +- test/integration/start_stop_delete_test.go | 6 +++--- test/integration/tunnel_test.go | 2 +- test/integration/util/kubectl_runner.go | 19 +++++++++++-------- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index e8f9859b1..f893f4e9e 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -40,7 +40,8 @@ import ( func testAddons(t *testing.T) { t.Parallel() - client, err := pkgutil.GetClient() + p := "minikube" + client, err := pkgutil.GetClient(p) if err != nil { t.Fatalf("Could not get kubernetes client: %v", err) } @@ -76,7 +77,8 @@ func readLineWithTimeout(b *bufio.Reader, timeout time.Duration) (string, error) func testDashboard(t *testing.T) { t.Parallel() - mk := NewMinikubeRunner(t, "--wait=false") + p := "minikube" + mk := NewMinikubeRunner(t, p, "--wait=false") cmd, out := mk.RunDaemon("dashboard --url") defer func() { err := cmd.Process.Kill() diff --git a/test/integration/cluster_dns_test.go b/test/integration/cluster_dns_test.go index 209c91fed..6e6e5e6b8 100644 --- a/test/integration/cluster_dns_test.go +++ b/test/integration/cluster_dns_test.go @@ -39,7 +39,7 @@ func testClusterDNS(t *testing.T) { } kr := util.NewKubectlRunner(t, p) - busybox := busyBoxPod(t, client, kr) + busybox := busyBoxPod(t, client, kr, p) defer func() { if _, err := kr.RunCommand([]string{"delete", "po", busybox}); err != nil { t.Errorf("delete failed: %v", err) @@ -62,12 +62,12 @@ func testClusterDNS(t *testing.T) { } } -func busyBoxPod(t *testing.T, c kubernetes.Interface, kr *util.KubectlRunner) string { +func busyBoxPod(t *testing.T, c kubernetes.Interface, kr *util.KubectlRunner, profile string) string { if _, err := kr.RunCommand([]string{"create", "-f", filepath.Join(*testdataDir, "busybox.yaml")}); err != nil { t.Fatalf("creating busybox pod: %s", err) } // TODO(tstromberg): Refactor WaitForBusyboxRunning to return name of pod. - if err := util.WaitForBusyboxRunning(t, "default", "minikube"); err != nil { + if err := util.WaitForBusyboxRunning(t, "default", profile); err != nil { t.Fatalf("Waiting for busybox pod to be up: %v", err) } diff --git a/test/integration/mount_test.go b/test/integration/mount_test.go index 5f5cdeec7..b062b370e 100644 --- a/test/integration/mount_test.go +++ b/test/integration/mount_test.go @@ -94,7 +94,7 @@ func testMounting(t *testing.T) { t.Fatal("mountTest failed with error:", err) } - if err := waitForPods(map[string]string{"integration-test": "busybox-mount"}); err != nil { + if err := waitForPods(map[string]string{"integration-test": "busybox-mount"}, p); err != nil { t.Fatalf("Error waiting for busybox mount pod to be up: %v", err) } t.Logf("Pods appear to be running") @@ -133,8 +133,8 @@ func writeFilesFromHost(mountedDir string, files []string, content string) error return nil } -func waitForPods(s map[string]string) error { - client, err := pkgutil.GetClient() +func waitForPods(s map[string]string, profile string) error { + client, err := pkgutil.GetClient(profile) if err != nil { return fmt.Errorf("getting kubernetes client: %v", err) } diff --git a/test/integration/pv_test.go b/test/integration/pv_test.go index 5c757b607..0bb77113c 100644 --- a/test/integration/pv_test.go +++ b/test/integration/pv_test.go @@ -71,7 +71,7 @@ func testProvisioning(t *testing.T) { // Check that the storage provisioner pod is running checkPodRunning := func() error { - client, err := commonutil.GetClient() + client, err := commonutil.GetClient(p) if err != nil { return errors.Wrap(err, "getting kubernetes client") } diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index 1b60922c3..bcba30e81 100644 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -85,12 +85,12 @@ func TestStartStop(t *testing.T) { // check for the current-context before and after the stop kr := util.NewKubectlRunner(t, p) - currentContext, err := kr.RunCommand([]string{"config", "current-context"}) + currentContext, err := kr.RunCommand([]string{"config", "current-context"}, false) if err != nil { t.Fatalf("Failed to fetch current-context") } - if strings.TrimRight(string(currentContext), "\n") != "minikube" { - t.Fatalf("got current-context - %q, want current-context %q", string(currentContext), "minikube") + if strings.TrimRight(string(currentContext), "\n") != p { + t.Fatalf("got current-context - %q, want current-context %q", string(currentContext), p) } checkStop := func() error { diff --git a/test/integration/tunnel_test.go b/test/integration/tunnel_test.go index b6a2ab4eb..6ce36ed74 100644 --- a/test/integration/tunnel_test.go +++ b/test/integration/tunnel_test.go @@ -73,7 +73,7 @@ func testTunnel(t *testing.T) { t.Fatalf("creating nginx ingress resource: %s", err) } - client, err := commonutil.GetClient() + client, err := commonutil.GetClient(p) if err != nil { t.Fatal(errors.Wrap(err, "getting kubernetes client")) diff --git a/test/integration/util/kubectl_runner.go b/test/integration/util/kubectl_runner.go index 93645cd74..1f33fb20f 100644 --- a/test/integration/util/kubectl_runner.go +++ b/test/integration/util/kubectl_runner.go @@ -51,12 +51,9 @@ func NewKubectlRunner(t *testing.T, profile ...string) *KubectlRunner { } // RunCommandParseOutput runs a command and parses the JSON output -func (k *KubectlRunner) RunCommandParseOutput(args []string, outputObj interface{}, setKubeContext ...bool) error { - kubecContextArg := fmt.Sprintf(" --context=%s", k.Profile) - args = append([]string{kubecContextArg}, args...) // prepending --context so it can be with with -- space - +func (k *KubectlRunner) RunCommandParseOutput(args []string, outputObj interface{}, useKubeContext ...bool) error { args = append(args, "-o=json") - output, err := k.RunCommand(args) + output, err := k.RunCommand(args, useKubeContext...) if err != nil { return err } @@ -68,9 +65,15 @@ func (k *KubectlRunner) RunCommandParseOutput(args []string, outputObj interface } // RunCommand runs a command, returning stdout -func (k *KubectlRunner) RunCommand(args []string) (stdout []byte, err error) { - kubecContextArg := fmt.Sprintf(" --context=%s", k.Profile) - args = append([]string{kubecContextArg}, args...) // prepending --context so it can be with with -- space +func (k *KubectlRunner) RunCommand(args []string, useKubeContext ...bool) (stdout []byte, err error) { + + if useKubeContext == nil { + useKubeContext = []bool{true} + } + if useKubeContext[0] { + kubecContextArg := fmt.Sprintf("--context=%s", k.Profile) + args = append([]string{kubecContextArg}, args...) // prepending --context so it can be with with -- space + } inner := func() error { cmd := exec.Command(k.BinaryPath, args...) -- GitLab