From e7095998548d4487e404800b1790913b9b73fb33 Mon Sep 17 00:00:00 2001 From: Michael Taufen Date: Sun, 10 Jul 2016 16:57:18 -0700 Subject: [PATCH] Modify framework pod creation functions to return the server's representation of the pod Since PodInterface.Create returns the server's representation of the pod, which may differ from the api.Pod object passed to Create, we do the same from the framework's pod creation functions. This is useful if e.g. you create pods using Pod.GenerateName rather than Pod.Name, and you still want to refer to pods by name later on (e.g. for deletion). --- test/e2e/framework/pods.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test/e2e/framework/pods.go b/test/e2e/framework/pods.go index c01b9add42f..5296689e66c 100644 --- a/test/e2e/framework/pods.go +++ b/test/e2e/framework/pods.go @@ -37,25 +37,31 @@ func (f *Framework) PodClient() unversioned.PodInterface { } // Create a new pod according to the framework specifications, and wait for it to start. -func (f *Framework) CreatePod(pod *api.Pod) { - f.CreatePodAsync(pod) - ExpectNoError(f.WaitForPodRunning(pod.Name)) +// Returns the server's representation of the pod. +func (f *Framework) CreatePod(pod *api.Pod) *api.Pod { + p := f.CreatePodAsync(pod) + ExpectNoError(f.WaitForPodRunning(p.Name)) + return p } // Create a new pod according to the framework specifications (don't wait for it to start). -func (f *Framework) CreatePodAsync(pod *api.Pod) { +// Returns the server's representation of the pod. +func (f *Framework) CreatePodAsync(pod *api.Pod) *api.Pod { f.MungePodSpec(pod) - _, err := f.PodClient().Create(pod) + p, err := f.PodClient().Create(pod) ExpectNoError(err, "Error creating Pod") + return p } // Batch version of CreatePod. All pods are created before waiting. -func (f *Framework) CreatePods(pods []*api.Pod) { - for _, pod := range pods { - f.CreatePodAsync(pod) +// Returns a slice, in the same order as pods, containing the server's representations of the pods. +func (f *Framework) CreatePods(pods []*api.Pod) []*api.Pod { + ps := make([]*api.Pod, len(pods)) + for i, pod := range pods { + ps[i] = f.CreatePodAsync(pod) } var wg sync.WaitGroup - for _, pod := range pods { + for _, pod := range ps { wg.Add(1) podName := pod.Name go func() { @@ -64,6 +70,7 @@ func (f *Framework) CreatePods(pods []*api.Pod) { }() } wg.Wait() + return ps } // Apply test-suite specific transformations to the pod spec.