mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #4631 from fabioy/fix-pods.go
Move the various "defer" calls before the creation in pods.go e2e test.
This commit is contained in:
commit
490624cfb7
@ -124,16 +124,14 @@ var _ = Describe("Pods", func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
By("submitting the pod to kubernetes")
|
By("submitting the pod to kubernetes")
|
||||||
|
// We call defer here in case there is a problem with
|
||||||
|
// the test so we can ensure that we clean up after
|
||||||
|
// ourselves
|
||||||
|
defer podClient.Delete(pod.Name)
|
||||||
_, err := podClient.Create(pod)
|
_, err := podClient.Create(pod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fail(fmt.Sprintf("Failed to create pod: %v", err))
|
Fail(fmt.Sprintf("Failed to create pod: %v", err))
|
||||||
}
|
}
|
||||||
defer func() {
|
|
||||||
// We call defer here in case there is a problem with
|
|
||||||
// the test so we can ensure that we clean up after
|
|
||||||
// ourselves
|
|
||||||
podClient.Delete(pod.Name)
|
|
||||||
}()
|
|
||||||
|
|
||||||
By("verifying the pod is in kubernetes")
|
By("verifying the pod is in kubernetes")
|
||||||
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
pods, err := podClient.List(labels.SelectorFromSet(labels.Set(map[string]string{"time": value})))
|
||||||
@ -183,14 +181,14 @@ var _ = Describe("Pods", func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
By("submitting the pod to kubernetes")
|
By("submitting the pod to kubernetes")
|
||||||
_, err := podClient.Create(pod)
|
|
||||||
if err != nil {
|
|
||||||
Fail(fmt.Sprintf("Failed to create pod: %v", err))
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
By("deleting the pod")
|
By("deleting the pod")
|
||||||
podClient.Delete(pod.Name)
|
podClient.Delete(pod.Name)
|
||||||
}()
|
}()
|
||||||
|
_, err := podClient.Create(pod)
|
||||||
|
if err != nil {
|
||||||
|
Fail(fmt.Sprintf("Failed to create pod: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
By("waiting for the pod to start running")
|
By("waiting for the pod to start running")
|
||||||
expectNoError(waitForPodRunning(c, pod.Name, 300*time.Second))
|
expectNoError(waitForPodRunning(c, pod.Name, 300*time.Second))
|
||||||
@ -243,13 +241,11 @@ var _ = Describe("Pods", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
defer c.Pods(api.NamespaceDefault).Delete(serverPod.Name)
|
||||||
_, 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))
|
||||||
}
|
}
|
||||||
defer func() {
|
|
||||||
c.Pods(api.NamespaceDefault).Delete(serverPod.Name)
|
|
||||||
}()
|
|
||||||
expectNoError(waitForPodRunning(c, serverPod.Name, 300*time.Second))
|
expectNoError(waitForPodRunning(c, serverPod.Name, 300*time.Second))
|
||||||
|
|
||||||
// This service exposes port 8080 of the test pod as a service on port 8765
|
// This service exposes port 8080 of the test pod as a service on port 8765
|
||||||
@ -275,13 +271,11 @@ var _ = Describe("Pods", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
defer c.Services(api.NamespaceDefault).Delete(svc.Name)
|
||||||
_, err = c.Services(api.NamespaceDefault).Create(svc)
|
_, err = c.Services(api.NamespaceDefault).Create(svc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fail(fmt.Sprintf("Failed to create service: %v", err))
|
Fail(fmt.Sprintf("Failed to create service: %v", err))
|
||||||
}
|
}
|
||||||
defer func() {
|
|
||||||
c.Services(api.NamespaceDefault).Delete(svc.Name)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// 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.
|
||||||
|
|
||||||
@ -305,13 +299,11 @@ var _ = Describe("Pods", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
defer c.Pods(api.NamespaceDefault).Delete(clientPod.Name)
|
||||||
_, 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))
|
||||||
}
|
}
|
||||||
defer func() {
|
|
||||||
c.Pods(api.NamespaceDefault).Delete(clientPod.Name)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Wait for client pod to complete.
|
// Wait for client pod to complete.
|
||||||
expectNoError(waitForPodRunning(c, clientPod.Name, 60*time.Second))
|
expectNoError(waitForPodRunning(c, clientPod.Name, 60*time.Second))
|
||||||
|
Loading…
Reference in New Issue
Block a user