Commit 3fbfeccc authored by Zach Loafman's avatar Zach Loafman

Merge pull request #4163 from rrati/e2e-services-4162

E2e services 4162
parents 079dd4db 70237e9c
/*
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 (
"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() {
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())
})
})
...@@ -23,132 +23,158 @@ import ( ...@@ -23,132 +23,158 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/golang/glog"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
// TestClusterDNS checks that cluster DNS works. var _ = Describe("Services", func() {
func TestClusterDNS(c *client.Client) bool { var c *client.Client
if testContext.provider == "vagrant" {
glog.Infof("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)") BeforeEach(func() {
return true c = loadClientOrDie()
} })
podClient := c.Pods(api.NamespaceDefault) It("should provide DNS for the cluster", func() {
if testContext.provider == "vagrant" {
//TODO: Wait for skyDNS By("Skipping test which is broken for vagrant (See https://github.com/GoogleCloudPlatform/kubernetes/issues/3580)")
return
// All the names we need to be able to resolve. }
namesToResolve := []string{
"kubernetes-ro", podClient := c.Pods(api.NamespaceDefault)
"kubernetes-ro.default",
"kubernetes-ro.default.kubernetes.local", //TODO: Wait for skyDNS
"google.com",
} // All the names we need to be able to resolve.
namesToResolve := []string{
probeCmd := "for i in `seq 1 600`; do " "kubernetes-ro",
for _, name := range namesToResolve { "kubernetes-ro.default",
probeCmd += fmt.Sprintf("wget -O /dev/null %s && echo OK > /results/%s;", name, name) "kubernetes-ro.default.kubernetes.local",
} "google.com",
probeCmd += "sleep 1; done" }
// Run a pod which probes DNS and exposes the results by HTTP. probeCmd := "for i in `seq 1 600`; do "
pod := &api.Pod{ for _, name := range namesToResolve {
TypeMeta: api.TypeMeta{ probeCmd += fmt.Sprintf("wget -O /dev/null %s && echo OK > /results/%s;", name, name)
Kind: "Pod", }
APIVersion: "v1beta1", probeCmd += "sleep 1; done"
},
ObjectMeta: api.ObjectMeta{ // Run a pod which probes DNS and exposes the results by HTTP.
Name: "dns-test-" + string(util.NewUUID()), By("creating a pod to probe DNS")
}, pod := &api.Pod{
Spec: api.PodSpec{ TypeMeta: api.TypeMeta{
Volumes: []api.Volume{ Kind: "Pod",
{ APIVersion: "v1beta1",
Name: "results", },
Source: api.VolumeSource{ ObjectMeta: api.ObjectMeta{
EmptyDir: &api.EmptyDir{}, Name: "dns-test-" + string(util.NewUUID()),
},
},
}, },
Containers: []api.Container{ Spec: api.PodSpec{
{ Volumes: []api.Volume{
Name: "webserver", {
Image: "kubernetes/test-webserver", Name: "results",
VolumeMounts: []api.VolumeMount{ Source: api.VolumeSource{
{ EmptyDir: &api.EmptyDir{},
Name: "results",
MountPath: "/results",
}, },
}, },
}, },
{ Containers: []api.Container{
Name: "pinger", {
Image: "busybox", Name: "webserver",
Command: []string{"sh", "-c", probeCmd}, Image: "kubernetes/test-webserver",
VolumeMounts: []api.VolumeMount{ VolumeMounts: []api.VolumeMount{
{ {
Name: "results", Name: "results",
MountPath: "/results", MountPath: "/results",
},
},
},
{
Name: "pinger",
Image: "busybox",
Command: []string{"sh", "-c", probeCmd},
VolumeMounts: []api.VolumeMount{
{
Name: "results",
MountPath: "/results",
},
}, },
}, },
}, },
}, },
}, }
}
_, err := podClient.Create(pod) By("submitting the pod to kuberenetes")
if err != nil { _, err := podClient.Create(pod)
glog.Errorf("Failed to create %s pod: %v", pod.Name, err) if err != nil {
return false Fail(fmt.Sprintf("Failed to create %s pod: %v", pod.Name, err))
} }
defer podClient.Delete(pod.Name) defer func() {
By("deleting the pod")
waitForPodRunning(c, pod.Name) defer GinkgoRecover()
pod, err = podClient.Get(pod.Name) podClient.Delete(pod.Name)
if err != nil { }()
glog.Errorf("Failed to get pod %s: %v", pod.Name, err)
return false By("waiting for the pod to start running")
} waitForPodRunning(c, pod.Name)
// Try to find results for each expected name. By("retrieving the pod")
var failed []string pod, err = podClient.Get(pod.Name)
for try := 1; try < 100; try++ { if err != nil {
failed = []string{} Fail(fmt.Sprintf("Failed to get pod %s: %v", pod.Name, err))
for _, name := range namesToResolve { }
_, err := c.Get().
Prefix("proxy"). // Try to find results for each expected name.
Resource("pods"). By("looking for the results for each expected name")
Namespace("default"). var failed []string
Name(pod.Name). for try := 1; try < 100; try++ {
Suffix("results", name). failed = []string{}
Do().Raw() for _, name := range namesToResolve {
if err != nil { _, err := c.Get().
failed = append(failed, name) Prefix("proxy").
glog.V(4).Infof("Lookup using %s for %s failed: %v", pod.Name, name, err) 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)
} }
if len(failed) == 0 { Expect(len(failed)).To(Equal(0))
break
// TODO: probe from the host, too.
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
}
} }
glog.Infof("lookups using %s failed for: %v", pod.Name, failed) Expect(foundRW).To(Equal(true))
time.Sleep(10 * time.Second) Expect(foundRO).To(Equal(true))
}
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())
}) })
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment