From de848cc3f098e042c9f037c0bed48bbbe0d35452 Mon Sep 17 00:00:00 2001 From: Robert Rati Date: Wed, 4 Feb 2015 09:21:37 -0500 Subject: [PATCH 1/5] Moved cluster_dns to create the new service test suite #4162 --- test/e2e/{cluster_dns.go => service.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/e2e/{cluster_dns.go => service.go} (100%) diff --git a/test/e2e/cluster_dns.go b/test/e2e/service.go similarity index 100% rename from test/e2e/cluster_dns.go rename to test/e2e/service.go From d44c1d5b842e3ea3b4e735752fcc5e39f798834a Mon Sep 17 00:00:00 2001 From: Robert Rati Date: Thu, 5 Feb 2015 08:50:07 -0500 Subject: [PATCH 2/5] Converted TestClusterDNS to native ginkgo syntax #4162 --- test/e2e/service.go | 235 ++++++++++++++++++++++---------------------- 1 file changed, 119 insertions(+), 116 deletions(-) diff --git a/test/e2e/service.go b/test/e2e/service.go index b64da904e7b..4880615720b 100644 --- a/test/e2e/service.go +++ b/test/e2e/service.go @@ -23,132 +23,135 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" - "github.com/golang/glog" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) -// TestClusterDNS checks that cluster DNS works. -func TestClusterDNS(c *client.Client) bool { - if testContext.provider == "vagrant" { - glog.Infof("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)") - return true - } +var _ = Describe("Services", func() { + var c *client.Client - podClient := c.Pods(api.NamespaceDefault) + BeforeEach(func() { + c = loadClientOrDie() + }) - //TODO: Wait for skyDNS + It("should provide DNS for the cluster", func() { + if testContext.provider == "vagrant" { + By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)") + } else { + podClient := c.Pods(api.NamespaceDefault) - // All the names we need to be able to resolve. - namesToResolve := []string{ - "kubernetes-ro", - "kubernetes-ro.default", - "kubernetes-ro.default.kubernetes.local", - "google.com", - } + //TODO: Wait for skyDNS - probeCmd := "for i in `seq 1 600`; do " - for _, name := range namesToResolve { - probeCmd += fmt.Sprintf("wget -O /dev/null %s && echo OK > /results/%s;", name, name) - } - probeCmd += "sleep 1; done" - - // Run a pod which probes DNS and exposes the results by HTTP. - pod := &api.Pod{ - TypeMeta: api.TypeMeta{ - Kind: "Pod", - APIVersion: "v1beta1", - }, - ObjectMeta: api.ObjectMeta{ - Name: "dns-test-" + string(util.NewUUID()), - }, - Spec: api.PodSpec{ - Volumes: []api.Volume{ - { - Name: "results", - Source: api.VolumeSource{ - EmptyDir: &api.EmptyDir{}, - }, - }, - }, - Containers: []api.Container{ - { - Name: "webserver", - Image: "kubernetes/test-webserver", - VolumeMounts: []api.VolumeMount{ - { - Name: "results", - MountPath: "/results", - }, - }, - }, - { - Name: "pinger", - Image: "busybox", - Command: []string{"sh", "-c", probeCmd}, - VolumeMounts: []api.VolumeMount{ - { - Name: "results", - MountPath: "/results", - }, - }, - }, - }, - }, - } - _, err := podClient.Create(pod) - if err != nil { - glog.Errorf("Failed to create %s pod: %v", pod.Name, err) - return false - } - defer podClient.Delete(pod.Name) - - waitForPodRunning(c, pod.Name) - pod, err = podClient.Get(pod.Name) - if err != nil { - glog.Errorf("Failed to get pod %s: %v", pod.Name, err) - return false - } - - // Try to find results for each expected name. - var failed []string - for try := 1; try < 100; try++ { - failed = []string{} - for _, name := range namesToResolve { - _, err := c.Get(). - Prefix("proxy"). - Resource("pods"). - Namespace("default"). - Name(pod.Name). - Suffix("results", name). - Do().Raw() - if err != nil { - failed = append(failed, name) - glog.V(4).Infof("Lookup using %s for %s failed: %v", pod.Name, name, err) + // All the names we need to be able to resolve. + namesToResolve := []string{ + "kubernetes-ro", + "kubernetes-ro.default", + "kubernetes-ro.default.kubernetes.local", + "google.com", } + + probeCmd := "for i in `seq 1 600`; do " + for _, name := range namesToResolve { + probeCmd += fmt.Sprintf("wget -O /dev/null %s && echo OK > /results/%s;", name, name) + } + probeCmd += "sleep 1; done" + + // Run a pod which probes DNS and exposes the results by HTTP. + By("creating a pod to probe DNS") + pod := &api.Pod{ + TypeMeta: api.TypeMeta{ + Kind: "Pod", + APIVersion: "v1beta1", + }, + ObjectMeta: api.ObjectMeta{ + Name: "dns-test-" + string(util.NewUUID()), + }, + Spec: api.PodSpec{ + Volumes: []api.Volume{ + { + Name: "results", + Source: api.VolumeSource{ + EmptyDir: &api.EmptyDir{}, + }, + }, + }, + Containers: []api.Container{ + { + Name: "webserver", + Image: "kubernetes/test-webserver", + VolumeMounts: []api.VolumeMount{ + { + Name: "results", + MountPath: "/results", + }, + }, + }, + { + Name: "pinger", + Image: "busybox", + Command: []string{"sh", "-c", probeCmd}, + VolumeMounts: []api.VolumeMount{ + { + Name: "results", + MountPath: "/results", + }, + }, + }, + }, + }, + } + + By("submitting the pod to kuberenetes") + _, err := podClient.Create(pod) + if err != nil { + Fail(fmt.Sprintf("Failed to create %s pod: %v", pod.Name, err)) + } + defer func() { + By("deleting the pod") + defer GinkgoRecover() + podClient.Delete(pod.Name) + }() + + + By("waiting for the pod to start running") + waitForPodRunning(c, pod.Name) + + By("retrieving the pod") + pod, err = podClient.Get(pod.Name) + if err != nil { + Fail(fmt.Sprintf("Failed to get pod %s: %v", pod.Name, err)) + } + + // Try to find results for each expected name. + By("looking for the results for each expected name") + var failed []string + for try := 1; try < 100; try++ { + failed = []string{} + for _, name := range namesToResolve { + _, err := c.Get(). + Prefix("proxy"). + Resource("pods"). + Namespace("default"). + Name(pod.Name). + Suffix("results", name). + Do().Raw() + if err != nil { + failed = append(failed, name) + fmt.Printf("Lookup using %s for %s failed: %v\n", pod.Name, name, err) + } + } + if len(failed) == 0 { + break + } + fmt.Printf("lookups using %s failed for: %v\n", pod.Name, failed) + time.Sleep(10 * time.Second) + } + Expect(len(failed)).To(Equal(0)) + + // TODO: probe from the host, too. + + fmt.Printf("DNS probes using %s succeeded\n", pod.Name) } - if len(failed) == 0 { - break - } - glog.Infof("lookups using %s failed for: %v", pod.Name, failed) - time.Sleep(10 * time.Second) - } - if len(failed) != 0 { - glog.Errorf("DNS using %s failed for: %v", pod.Name, failed) - return false - } - - // TODO: probe from the host, too. - - glog.Infof("DNS probes using %s succeeded", pod.Name) - return true -} - -var _ = Describe("TestClusterDNS", func() { - It("should pass", func() { - // TODO: Instead of OrDie, client should Fail the test if there's a problem. - // In general tests should Fail() instead of glog.Fatalf(). - Expect(TestClusterDNS(loadClientOrDie())).To(BeTrue()) }) }) From eefd7ace56915413f0cc9d1638a79065e1dafdad Mon Sep 17 00:00:00 2001 From: Robert Rati Date: Thu, 5 Feb 2015 08:59:41 -0500 Subject: [PATCH 3/5] Converted TestKubernetesROService to native ginkgo syntax #4162 --- test/e2e/roservice.go | 64 +++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/test/e2e/roservice.go b/test/e2e/roservice.go index a631fbcdb9c..421cbcdee7a 100644 --- a/test/e2e/roservice.go +++ b/test/e2e/roservice.go @@ -17,50 +17,42 @@ limitations under the License. package e2e import ( + "fmt" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/client" - "github.com/golang/glog" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) -func TestKubernetesROService(c *client.Client) bool { - svc := api.ServiceList{} - err := c.Get(). - Namespace("default"). - AbsPath("/api/v1beta1/proxy/services/kubernetes-ro/api/v1beta1/services"). - Do(). - Into(&svc) - if err != nil { - glog.Errorf("unexpected error listing services using ro service: %v", err) - return false - } - var foundRW, foundRO bool - for i := range svc.Items { - if svc.Items[i].Name == "kubernetes" { - foundRW = true - } - if svc.Items[i].Name == "kubernetes-ro" { - foundRO = true - } - } - if !foundRW { - glog.Error("no RW service found") - } - if !foundRO { - glog.Error("no RO service found") - } - if !foundRW || !foundRO { - return false - } - return true -} - var _ = Describe("TestKubernetesROService", func() { + var c *client.Client + + BeforeEach(func() { + c = loadClientOrDie() + }) + It("should pass", func() { - // TODO: Instead of OrDie, client should Fail the test if there's a problem. - // In general tests should Fail() instead of glog.Fatalf(). - Expect(TestKubernetesROService(loadClientOrDie())).To(BeTrue()) + svc := api.ServiceList{} + err := c.Get(). + Namespace("default"). + AbsPath("/api/v1beta1/proxy/services/kubernetes-ro/api/v1beta1/services"). + Do(). + Into(&svc) + if err != nil { + Fail(fmt.Sprintf("unexpected error listing services using ro service: %v", err)) + } + var foundRW, foundRO bool + for i := range svc.Items { + if svc.Items[i].Name == "kubernetes" { + foundRW = true + } + if svc.Items[i].Name == "kubernetes-ro" { + foundRO = true + } + } + Expect(foundRW).To(Equal(true)) + Expect(foundRO).To(Equal(true)) }) }) From d3e04cd2460c0ad4a7392bf37e39aa507a0924dd Mon Sep 17 00:00:00 2001 From: Robert Rati Date: Thu, 5 Feb 2015 09:05:45 -0500 Subject: [PATCH 4/5] Moved the ROService test into the services suite #4162 --- test/e2e/roservice.go | 58 ------------------------------------------- test/e2e/service.go | 23 +++++++++++++++++ 2 files changed, 23 insertions(+), 58 deletions(-) delete mode 100644 test/e2e/roservice.go diff --git a/test/e2e/roservice.go b/test/e2e/roservice.go deleted file mode 100644 index 421cbcdee7a..00000000000 --- a/test/e2e/roservice.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Copyright 2014 Google Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package e2e - -import ( - "fmt" - - "github.com/GoogleCloudPlatform/kubernetes/pkg/api" - "github.com/GoogleCloudPlatform/kubernetes/pkg/client" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("TestKubernetesROService", func() { - var c *client.Client - - BeforeEach(func() { - c = loadClientOrDie() - }) - - It("should pass", func() { - svc := api.ServiceList{} - err := c.Get(). - Namespace("default"). - AbsPath("/api/v1beta1/proxy/services/kubernetes-ro/api/v1beta1/services"). - Do(). - Into(&svc) - if err != nil { - Fail(fmt.Sprintf("unexpected error listing services using ro service: %v", err)) - } - var foundRW, foundRO bool - for i := range svc.Items { - if svc.Items[i].Name == "kubernetes" { - foundRW = true - } - if svc.Items[i].Name == "kubernetes-ro" { - foundRO = true - } - } - Expect(foundRW).To(Equal(true)) - Expect(foundRO).To(Equal(true)) - }) -}) diff --git a/test/e2e/service.go b/test/e2e/service.go index 4880615720b..781fbfdea37 100644 --- a/test/e2e/service.go +++ b/test/e2e/service.go @@ -154,4 +154,27 @@ var _ = Describe("Services", func() { fmt.Printf("DNS probes using %s succeeded\n", pod.Name) } }) + + It("should provide RW and RO services", func() { + svc := api.ServiceList{} + err := c.Get(). + Namespace("default"). + AbsPath("/api/v1beta1/proxy/services/kubernetes-ro/api/v1beta1/services"). + Do(). + Into(&svc) + if err != nil { + Fail(fmt.Sprintf("unexpected error listing services using ro service: %v", err)) + } + var foundRW, foundRO bool + for i := range svc.Items { + if svc.Items[i].Name == "kubernetes" { + foundRW = true + } + if svc.Items[i].Name == "kubernetes-ro" { + foundRO = true + } + } + Expect(foundRW).To(Equal(true)) + Expect(foundRO).To(Equal(true)) + }) }) From 70237e9cc608be1c3aece3ac7ed8b421cf21cb53 Mon Sep 17 00:00:00 2001 From: Robert Rati Date: Thu, 5 Feb 2015 12:53:03 -0500 Subject: [PATCH 5/5] Changed to return in the success case testing testContext instead of using an else statement. #4162 --- test/e2e/service.go | 228 ++++++++++++++++++++++---------------------- 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/test/e2e/service.go b/test/e2e/service.go index 781fbfdea37..c993e86dc43 100644 --- a/test/e2e/service.go +++ b/test/e2e/service.go @@ -38,121 +38,121 @@ var _ = Describe("Services", func() { It("should provide DNS for the cluster", func() { if testContext.provider == "vagrant" { By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)") - } else { - podClient := c.Pods(api.NamespaceDefault) - - //TODO: Wait for skyDNS - - // All the names we need to be able to resolve. - namesToResolve := []string{ - "kubernetes-ro", - "kubernetes-ro.default", - "kubernetes-ro.default.kubernetes.local", - "google.com", - } - - probeCmd := "for i in `seq 1 600`; do " - for _, name := range namesToResolve { - probeCmd += fmt.Sprintf("wget -O /dev/null %s && echo OK > /results/%s;", name, name) - } - probeCmd += "sleep 1; done" - - // Run a pod which probes DNS and exposes the results by HTTP. - By("creating a pod to probe DNS") - pod := &api.Pod{ - TypeMeta: api.TypeMeta{ - Kind: "Pod", - APIVersion: "v1beta1", - }, - ObjectMeta: api.ObjectMeta{ - Name: "dns-test-" + string(util.NewUUID()), - }, - Spec: api.PodSpec{ - Volumes: []api.Volume{ - { - Name: "results", - Source: api.VolumeSource{ - EmptyDir: &api.EmptyDir{}, - }, - }, - }, - Containers: []api.Container{ - { - Name: "webserver", - Image: "kubernetes/test-webserver", - VolumeMounts: []api.VolumeMount{ - { - Name: "results", - MountPath: "/results", - }, - }, - }, - { - Name: "pinger", - Image: "busybox", - Command: []string{"sh", "-c", probeCmd}, - VolumeMounts: []api.VolumeMount{ - { - Name: "results", - MountPath: "/results", - }, - }, - }, - }, - }, - } - - By("submitting the pod to kuberenetes") - _, err := podClient.Create(pod) - if err != nil { - Fail(fmt.Sprintf("Failed to create %s pod: %v", pod.Name, err)) - } - defer func() { - By("deleting the pod") - defer GinkgoRecover() - podClient.Delete(pod.Name) - }() - - - By("waiting for the pod to start running") - waitForPodRunning(c, pod.Name) - - By("retrieving the pod") - pod, err = podClient.Get(pod.Name) - if err != nil { - Fail(fmt.Sprintf("Failed to get pod %s: %v", pod.Name, err)) - } - - // Try to find results for each expected name. - By("looking for the results for each expected name") - var failed []string - for try := 1; try < 100; try++ { - failed = []string{} - for _, name := range namesToResolve { - _, err := c.Get(). - Prefix("proxy"). - Resource("pods"). - Namespace("default"). - Name(pod.Name). - Suffix("results", name). - Do().Raw() - if err != nil { - failed = append(failed, name) - fmt.Printf("Lookup using %s for %s failed: %v\n", pod.Name, name, err) - } - } - if len(failed) == 0 { - break - } - fmt.Printf("lookups using %s failed for: %v\n", pod.Name, failed) - time.Sleep(10 * time.Second) - } - Expect(len(failed)).To(Equal(0)) - - // TODO: probe from the host, too. - - fmt.Printf("DNS probes using %s succeeded\n", pod.Name) + return } + + podClient := c.Pods(api.NamespaceDefault) + + //TODO: Wait for skyDNS + + // All the names we need to be able to resolve. + namesToResolve := []string{ + "kubernetes-ro", + "kubernetes-ro.default", + "kubernetes-ro.default.kubernetes.local", + "google.com", + } + + probeCmd := "for i in `seq 1 600`; do " + for _, name := range namesToResolve { + probeCmd += fmt.Sprintf("wget -O /dev/null %s && echo OK > /results/%s;", name, name) + } + probeCmd += "sleep 1; done" + + // Run a pod which probes DNS and exposes the results by HTTP. + By("creating a pod to probe DNS") + pod := &api.Pod{ + TypeMeta: api.TypeMeta{ + Kind: "Pod", + APIVersion: "v1beta1", + }, + ObjectMeta: api.ObjectMeta{ + Name: "dns-test-" + string(util.NewUUID()), + }, + Spec: api.PodSpec{ + Volumes: []api.Volume{ + { + Name: "results", + Source: api.VolumeSource{ + EmptyDir: &api.EmptyDir{}, + }, + }, + }, + Containers: []api.Container{ + { + Name: "webserver", + Image: "kubernetes/test-webserver", + VolumeMounts: []api.VolumeMount{ + { + Name: "results", + MountPath: "/results", + }, + }, + }, + { + Name: "pinger", + Image: "busybox", + Command: []string{"sh", "-c", probeCmd}, + VolumeMounts: []api.VolumeMount{ + { + Name: "results", + MountPath: "/results", + }, + }, + }, + }, + }, + } + + By("submitting the pod to kuberenetes") + _, err := podClient.Create(pod) + if err != nil { + Fail(fmt.Sprintf("Failed to create %s pod: %v", pod.Name, err)) + } + defer func() { + By("deleting the pod") + defer GinkgoRecover() + podClient.Delete(pod.Name) + }() + + By("waiting for the pod to start running") + waitForPodRunning(c, pod.Name) + + By("retrieving the pod") + pod, err = podClient.Get(pod.Name) + if err != nil { + Fail(fmt.Sprintf("Failed to get pod %s: %v", pod.Name, err)) + } + + // Try to find results for each expected name. + By("looking for the results for each expected name") + var failed []string + for try := 1; try < 100; try++ { + failed = []string{} + for _, name := range namesToResolve { + _, err := c.Get(). + Prefix("proxy"). + Resource("pods"). + Namespace("default"). + Name(pod.Name). + Suffix("results", name). + Do().Raw() + if err != nil { + failed = append(failed, name) + fmt.Printf("Lookup using %s for %s failed: %v\n", pod.Name, name, err) + } + } + if len(failed) == 0 { + break + } + fmt.Printf("lookups using %s failed for: %v\n", pod.Name, failed) + time.Sleep(10 * time.Second) + } + Expect(len(failed)).To(Equal(0)) + + // TODO: probe from the host, too. + + fmt.Printf("DNS probes using %s succeeded\n", pod.Name) }) It("should provide RW and RO services", func() {