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).
This commit is contained in:
Michael Taufen
2016-07-10 16:57:18 -07:00
parent 710374b65f
commit e709599854

View File

@@ -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.