Merge pull request #4004 from filbranden/e2e_podsvcenv_remove_embedded_json

Use api.Pod and api.Service objects instead of JSON snippets
This commit is contained in:
Satnam Singh 2015-02-04 14:49:24 -08:00
commit 9ec61ce355

View File

@ -179,28 +179,22 @@ var _ = Describe("Pods", func() {
It("should contain environment variables for services", func() { It("should contain environment variables for services", func() {
// Make a pod that will be a service. // Make a pod that will be a service.
// This pod serves its hostname via HTTP. // This pod serves its hostname via HTTP.
serverPod := parsePodOrDie(`{ serverName := "server-envvars-" + string(util.NewUUID())
"kind": "Pod", serverPod := &api.Pod{
"apiVersion": "v1beta1", ObjectMeta: api.ObjectMeta{
"id": "srv", Name: serverName,
"desiredState": { Labels: map[string]string{"name": serverName},
"manifest": { },
"version": "v1beta1", Spec: api.PodSpec{
"id": "srv", Containers: []api.Container{
"containers": [{ {
"name": "srv", Name: "srv",
"image": "kubernetes/serve_hostname", Image: "kubernetes/serve_hostname",
"ports": [{ Ports: []api.Port{{ContainerPort: 9376, HostPort: 8080}},
"containerPort": 9376, },
"hostPort": 8080 },
}] },
}] }
}
},
"labels": {
"name": "srv"
}
}`)
_, err := c.Pods(api.NamespaceDefault).Create(serverPod) _, err := c.Pods(api.NamespaceDefault).Create(serverPod)
if err != nil { if err != nil {
Fail(fmt.Sprintf("Failed to create serverPod: %v", err)) Fail(fmt.Sprintf("Failed to create serverPod: %v", err))
@ -211,19 +205,28 @@ var _ = Describe("Pods", func() {
}() }()
waitForPodRunning(c, serverPod.Name) waitForPodRunning(c, serverPod.Name)
// This service exposes pod p's port 8080 as a service on port 8765 // This service exposes port 8080 of the test pod as a service on port 8765
svc := parseServiceOrDie(`{ // TODO(filbranden): We would like to use a unique service name such as:
"id": "fooservice", // svcName := "svc-envvars-" + randomSuffix()
"kind": "Service", // However, that affects the name of the environment variables which are the capitalized
"apiVersion": "v1beta1", // service name, so that breaks this test. One possibility is to tweak the variable names
"port": 8765, // to match the service. Another is to rethink environment variable names and possibly
"containerPort": 8080, // allow overriding the prefix in the service manifest.
"selector": { svcName := "fooservice"
"name": "p" svc := &api.Service{
} ObjectMeta: api.ObjectMeta{
}`) Name: svcName,
if err != nil { Labels: map[string]string{
Fail(fmt.Sprintf("Failed to delete service: %v", err)) "name": svcName,
},
},
Spec: api.ServiceSpec{
Port: 8765,
ContainerPort: util.NewIntOrStringFromInt(8080),
Selector: map[string]string{
"name": serverName,
},
},
} }
time.Sleep(2) time.Sleep(2)
_, err = c.Services(api.NamespaceDefault).Create(svc) _, err = c.Services(api.NamespaceDefault).Create(svc)
@ -238,24 +241,25 @@ var _ = Describe("Pods", func() {
// TODO: we don't have a way to wait for a service to be "running". // If this proves flaky, then we will need to retry the clientPod or insert a sleep. // TODO: we don't have a way to wait for a service to be "running". // If this proves flaky, then we will need to retry the clientPod or insert a sleep.
// Make a client pod that verifies that it has the service environment variables. // Make a client pod that verifies that it has the service environment variables.
clientPod := parsePodOrDie(`{ clientName := "client-envvars-" + string(util.NewUUID())
"apiVersion": "v1beta1", clientPod := &api.Pod{
"kind": "Pod", ObjectMeta: api.ObjectMeta{
"id": "env3", Name: clientName,
"desiredState": { Labels: map[string]string{"name": clientName},
"manifest": { },
"version": "v1beta1", Spec: api.PodSpec{
"id": "env3", Containers: []api.Container{
"restartPolicy": { "never": {} }, {
"containers": [{ Name: "env3cont",
"name": "env3cont", Image: "busybox",
"image": "busybox", Command: []string{"sh", "-c", "env"},
"command": ["sh", "-c", "env"] },
}] },
} RestartPolicy: api.RestartPolicy{
}, Never: &api.RestartPolicyNever{},
"labels": { "name": "env3" } },
}`) },
}
_, err = c.Pods(api.NamespaceDefault).Create(clientPod) _, err = c.Pods(api.NamespaceDefault).Create(clientPod)
if err != nil { if err != nil {
Fail(fmt.Sprintf("Failed to create pod: %v", err)) Fail(fmt.Sprintf("Failed to create pod: %v", err))