From 86ecc90fe2d75e534b42d9daed7ac0b51ae99011 Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Fri, 8 Sep 2017 11:01:10 -0700 Subject: [PATCH 1/3] Run busybox integration test in default namespace If we choose a random namespace, the test will fail since RBAC permissions will not be set up correctly. This also chooses a randomly generated name, so that if we are running an integration test while another busybox pod is still cleaning up, there are no errors --- test/integration/persistence_test.go | 7 ++----- test/integration/testdata/busybox.yaml | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/test/integration/persistence_test.go b/test/integration/persistence_test.go index 8d9246f820b4..60a525e9dbcf 100644 --- a/test/integration/persistence_test.go +++ b/test/integration/persistence_test.go @@ -34,11 +34,8 @@ func TestPersistence(t *testing.T) { kubectlRunner := util.NewKubectlRunner(t) podPath, _ := filepath.Abs("testdata/busybox.yaml") - podNamespace := kubectlRunner.CreateRandomNamespace() - defer kubectlRunner.DeleteNamespace(podNamespace) - // Create a pod and wait for it to be running. - if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath, "--namespace=" + podNamespace}); err != nil { + if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil { t.Fatalf("Error creating test pod: %s", err) } @@ -47,7 +44,7 @@ func TestPersistence(t *testing.T) { t.Fatalf("waiting for dashboard to be up: %s", err) } - if err := util.WaitForBusyboxRunning(t, podNamespace); err != nil { + if err := util.WaitForBusyboxRunning(t, "default"); err != nil { t.Fatalf("waiting for busybox to be up: %s", err) } diff --git a/test/integration/testdata/busybox.yaml b/test/integration/testdata/busybox.yaml index a200d158dcc4..3c708b5018b6 100644 --- a/test/integration/testdata/busybox.yaml +++ b/test/integration/testdata/busybox.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Pod metadata: - name: busybox + generateName: busybox- labels: integration-test: busybox spec: From f966c8cf31a594949158358e07aaa289d1f11eba Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Fri, 8 Sep 2017 15:09:52 -0700 Subject: [PATCH 2/3] Add NewMinikubeRunner, separate start args * Separate start args from args passed to every command. This is so that we can call `minikube logs` and `minikube status` with the proper flags (for the bootstrapper) * Add a NewMinikubeRunner function to make getting a minikube runner easier. --- Makefile | 6 ++--- hack/jenkins/common.sh | 2 +- test/integration/addons_test.go | 11 ++-------- test/integration/cluster_dns_test.go | 18 +++++++++++++-- test/integration/cluster_env_test.go | 5 +---- test/integration/cluster_logs_test.go | 9 ++------ test/integration/cluster_ssh_test.go | 8 +------ test/integration/docker_test.go | 11 +++------- test/integration/flags.go | 12 ++++++++++ test/integration/functional_test.go | 8 ++----- test/integration/iso_test.go | 22 ++++--------------- test/integration/mount_test.go | 5 +---- test/integration/persistence_test.go | 2 +- test/integration/start_stop_delete_test.go | 5 +---- test/integration/util/util.go | 9 ++++++-- test/integration/versioned_functional_test.go | 5 +---- 16 files changed, 58 insertions(+), 80 deletions(-) mode change 100644 => 100755 Makefile mode change 100644 => 100755 hack/jenkins/common.sh mode change 100644 => 100755 test/integration/docker_test.go mode change 100644 => 100755 test/integration/functional_test.go diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 5423ec69757e..d3f42aaa5657 --- a/Makefile +++ b/Makefile @@ -152,15 +152,15 @@ test-iso: .PHONY: integration integration: out/minikube - go test -v -test.timeout=30m $(REPOPATH)/test/integration --tags="$(MINIKUBE_INTEGRATION_BUILD_TAGS)" --minikube-args="$(MINIKUBE_ARGS)" + go test -v -test.timeout=30m $(REPOPATH)/test/integration --tags="$(MINIKUBE_INTEGRATION_BUILD_TAGS)" $(TEST_ARGS) .PHONY: integration-none-driver integration-none-driver: e2e-linux-amd64 out/minikube-linux-amd64 - sudo -E out/e2e-linux-amd64 -testdata-dir "test/integration/testdata" -minikube-args="--vm-driver=none --alsologtostderr" -test.v -test.timeout=30m -binary=out/minikube-linux-amd64 + sudo -E out/e2e-linux-amd64 -testdata-dir "test/integration/testdata" -minikube-start-args="--vm-driver=none" -test.v -test.timeout=30m -binary=out/minikube-linux-amd64 $(TEST_ARGS) .PHONY: integration-versioned integration-versioned: out/minikube - go test -v -test.timeout=30m $(REPOPATH)/test/integration --tags="$(MINIKUBE_INTEGRATION_BUILD_TAGS) versioned" --minikube-args="$(MINIKUBE_ARGS)" + go test -v -test.timeout=30m $(REPOPATH)/test/integration --tags="$(MINIKUBE_INTEGRATION_BUILD_TAGS) versioned" $(TEST_ARGS) .PHONY: test test: pkg/minikube/assets/assets.go diff --git a/hack/jenkins/common.sh b/hack/jenkins/common.sh old mode 100644 new mode 100755 index 0bbedfd6f882..12fccf988b4f --- a/hack/jenkins/common.sh +++ b/hack/jenkins/common.sh @@ -83,7 +83,7 @@ find ~/.minikube || true # Allow this to fail, we'll switch on the return code below. set +e -${SUDO_PREFIX}out/e2e-${OS_ARCH} -minikube-args="--vm-driver=${VM_DRIVER} --v=10 --logtostderr" -test.v -test.timeout=30m -binary=out/minikube-${OS_ARCH} +${SUDO_PREFIX}out/e2e-${OS_ARCH} -minikube-start-args="--vm-driver=${VM_DRIVER}" -minikube-args="--v=10 --logtostderr ${EXTRA_ARGS}" -test.v -test.timeout=30m -binary=out/minikube-${OS_ARCH} result=$? set -e diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index 218856dd3330..674283c3a93b 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -44,11 +44,7 @@ func testAddons(t *testing.T) { func testDashboard(t *testing.T) { t.Parallel() - minikubeRunner := util.MinikubeRunner{ - BinaryPath: *binaryPath, - Args: *args, - T: t, - } + minikubeRunner := NewMinikubeRunner(t) if err := util.WaitForDashboardRunning(t); err != nil { t.Fatalf("waiting for dashboard to be up: %s", err) @@ -73,10 +69,7 @@ func testDashboard(t *testing.T) { func testServicesList(t *testing.T) { t.Parallel() - minikubeRunner := util.MinikubeRunner{ - BinaryPath: *binaryPath, - Args: *args, - T: t} + minikubeRunner := NewMinikubeRunner(t) checkServices := func() error { output := minikubeRunner.RunCommand("service list", false) diff --git a/test/integration/cluster_dns_test.go b/test/integration/cluster_dns_test.go index b2a94612b153..8c4411b4c06d 100644 --- a/test/integration/cluster_dns_test.go +++ b/test/integration/cluster_dns_test.go @@ -23,6 +23,9 @@ import ( "strings" "testing" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + pkgutil "k8s.io/minikube/pkg/util" + "k8s.io/minikube/test/integration/util" ) @@ -33,9 +36,12 @@ func testClusterDNS(t *testing.T) { } kubectlRunner := util.NewKubectlRunner(t) - podName := "busybox" podPath := filepath.Join(*testdataDir, "busybox.yaml") - defer kubectlRunner.RunCommand([]string{"delete", "-f", podPath}) + + client, err := pkgutil.GetClient() + if err != nil { + t.Fatalf("Error getting kubernetes client %s", err) + } if _, err := kubectlRunner.RunCommand([]string{"create", "-f", podPath}); err != nil { t.Fatalf("creating busybox pod: %s", err) @@ -44,6 +50,14 @@ func testClusterDNS(t *testing.T) { if err := util.WaitForBusyboxRunning(t, "default"); err != nil { t.Fatalf("Waiting for busybox pod to be up: %s", err) } + listOpts := metav1.ListOptions{LabelSelector: "integration-test=busybox"} + pods, err := client.CoreV1().Pods("default").List(listOpts) + if len(pods.Items) == 0 { + t.Fatal("Expected a busybox pod to be running") + } + + podName := pods.Items[0].Name + defer kubectlRunner.RunCommand([]string{"delete", "po", podName}) dnsByteArr, err := kubectlRunner.RunCommand([]string{"exec", podName, "nslookup", "kubernetes"}) diff --git a/test/integration/cluster_env_test.go b/test/integration/cluster_env_test.go index e45036eb3089..04ba05ce09c2 100644 --- a/test/integration/cluster_env_test.go +++ b/test/integration/cluster_env_test.go @@ -29,10 +29,7 @@ import ( func testClusterEnv(t *testing.T) { t.Parallel() - minikubeRunner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} + minikubeRunner := NewMinikubeRunner(t) dockerEnvVars := minikubeRunner.RunCommand("docker-env", true) if err := minikubeRunner.SetEnvFromEnvCmdOutput(dockerEnvVars); err != nil { diff --git a/test/integration/cluster_logs_test.go b/test/integration/cluster_logs_test.go index 51e180f93d61..51ad15bee537 100644 --- a/test/integration/cluster_logs_test.go +++ b/test/integration/cluster_logs_test.go @@ -21,19 +21,14 @@ package integration import ( "strings" "testing" - - "k8s.io/minikube/test/integration/util" ) func testClusterLogs(t *testing.T) { t.Parallel() - minikubeRunner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} + minikubeRunner := NewMinikubeRunner(t) minikubeRunner.EnsureRunning() + logsCmdOutput := minikubeRunner.GetLogs() - logsCmdOutput := minikubeRunner.RunCommand("logs", true) //check for # of lines or check for strings logWords := []string{"minikube", ".go"} for _, logWord := range logWords { diff --git a/test/integration/cluster_ssh_test.go b/test/integration/cluster_ssh_test.go index bc6835c28cd4..5c57f67276b5 100644 --- a/test/integration/cluster_ssh_test.go +++ b/test/integration/cluster_ssh_test.go @@ -21,17 +21,11 @@ package integration import ( "strings" "testing" - - "k8s.io/minikube/test/integration/util" ) func testClusterSSH(t *testing.T) { t.Parallel() - minikubeRunner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} - + minikubeRunner := NewMinikubeRunner(t) expectedStr := "hello" sshCmdOutput := minikubeRunner.RunCommand("ssh echo "+expectedStr, true) if !strings.Contains(sshCmdOutput, expectedStr) { diff --git a/test/integration/docker_test.go b/test/integration/docker_test.go old mode 100644 new mode 100755 index 854efdd72d35..8ae5cceb6a65 --- a/test/integration/docker_test.go +++ b/test/integration/docker_test.go @@ -22,22 +22,17 @@ import ( "fmt" "strings" "testing" - - "k8s.io/minikube/test/integration/util" ) func TestDocker(t *testing.T) { - minikubeRunner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} + minikubeRunner := NewMinikubeRunner(t) - if strings.Contains(*args, "--vm-driver=none") { + if strings.Contains(minikubeRunner.StartArgs, "--vm-driver=none") { t.Skip("skipping test as none driver does not bundle docker") } minikubeRunner.RunCommand("delete", false) - startCmd := fmt.Sprintf("start %s %s", minikubeRunner.Args, "--docker-env=FOO=BAR --docker-env=BAZ=BAT --docker-opt=debug --docker-opt=icc=true") + startCmd := fmt.Sprintf("start %s %s %s", minikubeRunner.StartArgs, minikubeRunner.Args, "--docker-env=FOO=BAR --docker-env=BAZ=BAT --docker-opt=debug --docker-opt=icc=true") minikubeRunner.RunCommand(startCmd, true) minikubeRunner.EnsureRunning() diff --git a/test/integration/flags.go b/test/integration/flags.go index 7f856bff521e..89db1fda0b36 100644 --- a/test/integration/flags.go +++ b/test/integration/flags.go @@ -20,6 +20,8 @@ import ( "flag" "os" "testing" + + "k8s.io/minikube/test/integration/util" ) func TestMain(m *testing.M) { @@ -29,4 +31,14 @@ func TestMain(m *testing.M) { var binaryPath = flag.String("binary", "../../out/minikube", "path to minikube binary") var args = flag.String("minikube-args", "", "Arguments to pass to minikube") +var startArgs = flag.String("minikube-start-args", "", "Arguments to pass to minikube start") var testdataDir = flag.String("testdata-dir", "testdata", "the directory relative to test/integration where the testdata lives") + +func NewMinikubeRunner(t *testing.T) util.MinikubeRunner { + return util.MinikubeRunner{ + Args: *args, + BinaryPath: *binaryPath, + StartArgs: *startArgs, + T: t, + } +} diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go old mode 100644 new mode 100755 index 974277d41485..95c8416bf98e --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -24,14 +24,10 @@ import ( "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/machine" - "k8s.io/minikube/test/integration/util" ) func TestFunctional(t *testing.T) { - minikubeRunner := util.MinikubeRunner{ - BinaryPath: *binaryPath, - Args: *args, - T: t} + minikubeRunner := NewMinikubeRunner(t) minikubeRunner.EnsureRunning() integrationTestImages := []string{"busybox:glibc"} if err := machine.CacheImages(integrationTestImages, constants.ImageCacheDir); err != nil { @@ -51,7 +47,7 @@ func TestFunctional(t *testing.T) { t.Run("ServicesList", testServicesList) t.Run("Provisioning", testProvisioning) - if !strings.Contains(*args, "--vm-driver=none") { + if !strings.Contains(minikubeRunner.StartArgs, "--vm-driver=none") { t.Run("EnvVars", testClusterEnv) t.Run("SSH", testClusterSSH) // t.Run("Mounting", testMounting) diff --git a/test/integration/iso_test.go b/test/integration/iso_test.go index 651d0d451496..8de6ffb6d4dd 100644 --- a/test/integration/iso_test.go +++ b/test/integration/iso_test.go @@ -22,16 +22,11 @@ import ( "fmt" "strings" "testing" - - "k8s.io/minikube/test/integration/util" ) func TestISO(t *testing.T) { - minikubeRunner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} + minikubeRunner := NewMinikubeRunner(t) minikubeRunner.RunCommand("delete", true) minikubeRunner.Start() @@ -42,10 +37,7 @@ func TestISO(t *testing.T) { } func testMountPermissions(t *testing.T) { - minikubeRunner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} + minikubeRunner := NewMinikubeRunner(t) // test mount permissions mountPoints := []string{"/Users", "/hosthome"} perms := "drwxr-xr-x" @@ -67,10 +59,7 @@ func testMountPermissions(t *testing.T) { } func testPackages(t *testing.T) { - minikubeRunner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} + minikubeRunner := NewMinikubeRunner(t) packages := []string{ "git", @@ -92,10 +81,7 @@ func testPackages(t *testing.T) { } func testPersistence(t *testing.T) { - minikubeRunner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} + minikubeRunner := NewMinikubeRunner(t) for _, dir := range []string{ "/data", diff --git a/test/integration/mount_test.go b/test/integration/mount_test.go index 8394e593f2f6..e902347715a1 100644 --- a/test/integration/mount_test.go +++ b/test/integration/mount_test.go @@ -36,10 +36,7 @@ func testMounting(t *testing.T) { if strings.Contains(*args, "--vm-driver=none") { t.Skip("skipping test for none driver as it does not need mount") } - minikubeRunner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} + minikubeRunner := NewMinikubeRunner(t) tempDir, err := ioutil.TempDir("", "mounttest") if err != nil { diff --git a/test/integration/persistence_test.go b/test/integration/persistence_test.go index 60a525e9dbcf..35730584393a 100644 --- a/test/integration/persistence_test.go +++ b/test/integration/persistence_test.go @@ -28,7 +28,7 @@ import ( ) func TestPersistence(t *testing.T) { - minikubeRunner := util.MinikubeRunner{BinaryPath: *binaryPath, T: t} + minikubeRunner := NewMinikubeRunner(t) minikubeRunner.EnsureRunning() kubectlRunner := util.NewKubectlRunner(t) diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index c55280dabba9..d52b6bfab115 100755 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -30,10 +30,7 @@ import ( func TestStartStop(t *testing.T) { - runner := util.MinikubeRunner{ - Args: *args, - BinaryPath: *binaryPath, - T: t} + runner := NewMinikubeRunner(t) runner.RunCommand("delete", false) runner.CheckStatus(state.None.String()) diff --git a/test/integration/util/util.go b/test/integration/util/util.go index f72681cd19b5..154bc984467b 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -42,6 +42,7 @@ type MinikubeRunner struct { T *testing.T BinaryPath string Args string + StartArgs string } func (m *MinikubeRunner) Run(cmd string) error { @@ -103,7 +104,7 @@ func (m *MinikubeRunner) SSH(command string) (string, error) { } func (m *MinikubeRunner) Start() { - m.RunCommand(fmt.Sprintf("start %s", m.Args), true) + m.RunCommand(fmt.Sprintf("start %s %s", m.StartArgs, m.Args), true) } func (m *MinikubeRunner) EnsureRunning() { @@ -129,7 +130,11 @@ func (m *MinikubeRunner) SetEnvFromEnvCmdOutput(dockerEnvVars string) error { } func (m *MinikubeRunner) GetStatus() string { - return m.RunCommand("status --format={{.MinikubeStatus}}", true) + return m.RunCommand(fmt.Sprintf("status --format={{.MinikubeStatus}} %s", m.Args), true) +} + +func (m *MinikubeRunner) GetLogs() string { + return m.RunCommand(fmt.Sprintf("logs %s", m.Args), true) } func (m *MinikubeRunner) CheckStatus(desired string) { diff --git a/test/integration/versioned_functional_test.go b/test/integration/versioned_functional_test.go index 19de279c90f9..554be97b1458 100644 --- a/test/integration/versioned_functional_test.go +++ b/test/integration/versioned_functional_test.go @@ -36,10 +36,7 @@ func TestVersionedFunctional(t *testing.T) { var minikubeRunner util.MinikubeRunner for _, version := range k8sVersions { vArgs := fmt.Sprintf("%s --kubernetes-version %s", *args, version.Version) - minikubeRunner = util.MinikubeRunner{ - BinaryPath: *binaryPath, - Args: vArgs, - T: t} + minikubeRunner = NewMinikubeRunner(t) minikubeRunner.EnsureRunning() t.Run("Status", testClusterStatus) From 9747484e9e1073f9ec793b84b2e61637bbb1c4ca Mon Sep 17 00:00:00 2001 From: Matt Rickard Date: Thu, 7 Sep 2017 19:49:42 -0700 Subject: [PATCH 3/3] Move k8s utils to pkg/util --- {test/integration => pkg}/util/kubernetes.go | 62 +++++++++++--------- test/integration/addons_test.go | 5 +- test/integration/mount_test.go | 5 +- test/integration/util/util.go | 18 +++--- 4 files changed, 49 insertions(+), 41 deletions(-) rename {test/integration => pkg}/util/kubernetes.go (77%) mode change 100644 => 100755 diff --git a/test/integration/util/kubernetes.go b/pkg/util/kubernetes.go old mode 100644 new mode 100755 similarity index 77% rename from test/integration/util/kubernetes.go rename to pkg/util/kubernetes.go index ee6ab583a484..04170e2e2658 --- a/test/integration/util/kubernetes.go +++ b/pkg/util/kubernetes.go @@ -18,7 +18,6 @@ package util import ( "fmt" - "testing" "time" "github.com/pkg/errors" @@ -30,11 +29,13 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/watch" + "k8s.io/kubernetes/cmd/kubeadm/app/constants" apierrs "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/kubernetes" "k8s.io/client-go/pkg/api/v1" + "github.com/golang/glog" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/clientcmd" ) @@ -109,31 +110,36 @@ func StartPods(c kubernetes.Interface, namespace string, pod v1.Pod, waitForRunn // Wait up to 10 minutes for all matching pods to become Running and at least one // matching pod exists. func WaitForPodsWithLabelRunning(c kubernetes.Interface, ns string, label labels.Selector) error { - running := false - PodStore := NewPodStore(c, ns, label, fields.Everything()) - defer PodStore.Stop() -waitLoop: - for start := time.Now(); time.Since(start) < 10*time.Minute; time.Sleep(250 * time.Millisecond) { - pods := PodStore.List() - if len(pods) == 0 { - continue waitLoop + lastKnownPodNumber := -1 + return wait.PollImmediate(constants.APICallRetryInterval, time.Minute*10, func() (bool, error) { + listOpts := metav1.ListOptions{LabelSelector: label.String()} + pods, err := c.CoreV1().Pods(ns).List(listOpts) + if err != nil { + glog.Infof("error getting Pods with label selector %q [%v]\n", label.String(), err) + return false, nil + } + + if lastKnownPodNumber != len(pods.Items) { + glog.Infof("Found %d Pods for label selector %s\n", len(pods.Items), label.String()) + lastKnownPodNumber = len(pods.Items) + } + + if len(pods.Items) == 0 { + return false, nil } - for _, p := range pods { - if p.Status.Phase != v1.PodRunning { - continue waitLoop + + for _, pod := range pods.Items { + if pod.Status.Phase != v1.PodRunning { + return false, nil } } - running = true - break - } - if !running { - return fmt.Errorf("Timeout while waiting for pods with labels %q to be running", label.String()) - } - return nil + + return true, nil + }) } // WaitForRCToStabilize waits till the RC has a matching generation/replica count between spec and status. -func WaitForRCToStabilize(t *testing.T, c kubernetes.Interface, ns, name string, timeout time.Duration) error { +func WaitForRCToStabilize(c kubernetes.Interface, ns, name string, timeout time.Duration) error { options := metav1.ListOptions{FieldSelector: fields.Set{ "metadata.name": name, "metadata.namespace": ns, @@ -154,7 +160,7 @@ func WaitForRCToStabilize(t *testing.T, c kubernetes.Interface, ns, name string, *(rc.Spec.Replicas) == rc.Status.Replicas { return true, nil } - t.Logf("Waiting for rc %s to stabilize, generation %v observed generation %v spec.replicas %d status.replicas %d", + glog.Infof("Waiting for rc %s to stabilize, generation %v observed generation %v spec.replicas %d status.replicas %d", name, rc.Generation, rc.Status.ObservedGeneration, *(rc.Spec.Replicas), rc.Status.Replicas) } return false, nil @@ -163,21 +169,21 @@ func WaitForRCToStabilize(t *testing.T, c kubernetes.Interface, ns, name string, } // WaitForService waits until the service appears (exist == true), or disappears (exist == false) -func WaitForService(t *testing.T, c kubernetes.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error { +func WaitForService(c kubernetes.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error { err := wait.PollImmediate(interval, timeout, func() (bool, error) { _, err := c.Core().Services(namespace).Get(name, metav1.GetOptions{}) switch { case err == nil: - t.Logf("Service %s in namespace %s found.", name, namespace) + glog.Infof("Service %s in namespace %s found.", name, namespace) return exist, nil case apierrs.IsNotFound(err): - t.Logf("Service %s in namespace %s disappeared.", name, namespace) + glog.Infof("Service %s in namespace %s disappeared.", name, namespace) return !exist, nil case !IsRetryableAPIError(err): - t.Logf("Non-retryable failure while getting service.") + glog.Infof("Non-retryable failure while getting service.") return false, err default: - t.Logf("Get service %s in namespace %s failed: %v", name, namespace, err) + glog.Infof("Get service %s in namespace %s failed: %v", name, namespace, err) return false, nil } }) @@ -189,9 +195,9 @@ func WaitForService(t *testing.T, c kubernetes.Interface, namespace, name string } //WaitForServiceEndpointsNum waits until the amount of endpoints that implement service to expectNum. -func WaitForServiceEndpointsNum(t *testing.T, c kubernetes.Interface, namespace, serviceName string, expectNum int, interval, timeout time.Duration) error { +func WaitForServiceEndpointsNum(c kubernetes.Interface, namespace, serviceName string, expectNum int, interval, timeout time.Duration) error { return wait.Poll(interval, timeout, func() (bool, error) { - t.Logf("Waiting for amount of service:%s endpoints to be %d", serviceName, expectNum) + glog.Infof("Waiting for amount of service:%s endpoints to be %d", serviceName, expectNum) list, err := c.Core().Endpoints(namespace).List(metav1.ListOptions{}) if err != nil { return false, err diff --git a/test/integration/addons_test.go b/test/integration/addons_test.go index 674283c3a93b..dfdba1bed1d6 100644 --- a/test/integration/addons_test.go +++ b/test/integration/addons_test.go @@ -27,17 +27,18 @@ import ( "time" "k8s.io/apimachinery/pkg/labels" + pkgutil "k8s.io/minikube/pkg/util" "k8s.io/minikube/test/integration/util" ) func testAddons(t *testing.T) { t.Parallel() - client, err := util.GetClient() + client, err := pkgutil.GetClient() if err != nil { t.Fatalf("Could not get kubernetes client: %s", err) } selector := labels.SelectorFromSet(labels.Set(map[string]string{"component": "kube-addon-manager"})) - if err := util.WaitForPodsWithLabelRunning(client, "kube-system", selector); err != nil { + if err := pkgutil.WaitForPodsWithLabelRunning(client, "kube-system", selector); err != nil { t.Errorf("Error waiting for addon manager to be up") } } diff --git a/test/integration/mount_test.go b/test/integration/mount_test.go index e902347715a1..b6ed7d3745ee 100644 --- a/test/integration/mount_test.go +++ b/test/integration/mount_test.go @@ -28,6 +28,7 @@ import ( "time" "k8s.io/apimachinery/pkg/labels" + pkgutil "k8s.io/minikube/pkg/util" "k8s.io/minikube/test/integration/util" ) @@ -76,12 +77,12 @@ func testMounting(t *testing.T) { t.Fatal("mountTest failed with error:", err) } - client, err := util.GetClient() + client, err := pkgutil.GetClient() if err != nil { t.Fatalf("getting kubernetes client: %s", err) } selector := labels.SelectorFromSet(labels.Set(map[string]string{"integration-test": "busybox-mount"})) - if err := util.WaitForPodsWithLabelRunning(client, "default", selector); err != nil { + if err := pkgutil.WaitForPodsWithLabelRunning(client, "default", selector); err != nil { t.Fatalf("Error waiting for busybox mount pod to be up: %s", err) } diff --git a/test/integration/util/util.go b/test/integration/util/util.go index 154bc984467b..6e4db51f8056 100644 --- a/test/integration/util/util.go +++ b/test/integration/util/util.go @@ -217,26 +217,26 @@ func (k *KubectlRunner) DeleteNamespace(namespace string) error { } func WaitForBusyboxRunning(t *testing.T, namespace string) error { - client, err := GetClient() + client, err := commonutil.GetClient() if err != nil { return errors.Wrap(err, "getting kubernetes client") } selector := labels.SelectorFromSet(labels.Set(map[string]string{"integration-test": "busybox"})) - return WaitForPodsWithLabelRunning(client, namespace, selector) + return commonutil.WaitForPodsWithLabelRunning(client, namespace, selector) } func WaitForDNSRunning(t *testing.T) error { - client, err := GetClient() + client, err := commonutil.GetClient() if err != nil { return errors.Wrap(err, "getting kubernetes client") } selector := labels.SelectorFromSet(labels.Set(map[string]string{"k8s-app": "kube-dns"})) - if err := WaitForPodsWithLabelRunning(client, "kube-system", selector); err != nil { + if err := commonutil.WaitForPodsWithLabelRunning(client, "kube-system", selector); err != nil { return errors.Wrap(err, "waiting for kube-dns pods") } - if err := WaitForService(t, client, "kube-system", "kube-dns", true, time.Millisecond*500, time.Minute*10); err != nil { + if err := commonutil.WaitForService(client, "kube-system", "kube-dns", true, time.Millisecond*500, time.Minute*10); err != nil { t.Errorf("Error waiting for kube-dns service to be up") } @@ -244,19 +244,19 @@ func WaitForDNSRunning(t *testing.T) error { } func WaitForDashboardRunning(t *testing.T) error { - client, err := GetClient() + client, err := commonutil.GetClient() if err != nil { return errors.Wrap(err, "getting kubernetes client") } - if err := WaitForRCToStabilize(t, client, "kube-system", "kubernetes-dashboard", time.Minute*10); err != nil { + if err := commonutil.WaitForRCToStabilize(client, "kube-system", "kubernetes-dashboard", time.Minute*10); err != nil { return errors.Wrap(err, "waiting for dashboard RC to stabilize") } - if err := WaitForService(t, client, "kube-system", "kubernetes-dashboard", true, time.Millisecond*500, time.Minute*10); err != nil { + if err := commonutil.WaitForService(client, "kube-system", "kubernetes-dashboard", true, time.Millisecond*500, time.Minute*10); err != nil { return errors.Wrap(err, "waiting for dashboard service to be up") } - if err := WaitForServiceEndpointsNum(t, client, "kube-system", "kubernetes-dashboard", 1, time.Second*3, time.Minute*10); err != nil { + if err := commonutil.WaitForServiceEndpointsNum(client, "kube-system", "kubernetes-dashboard", 1, time.Second*3, time.Minute*10); err != nil { return errors.Wrap(err, "waiting for one dashboard endpoint to be up") }