Merge pull request #28747 from mtaufen/framework_pods

Automatic merge from submit-queue

Return server's representation of pod from framework pod creation functions

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

cc @timstclair
pull/6/head
k8s-merge-robot 2016-07-11 20:06:39 -07:00 committed by GitHub
commit b840f039cc
1 changed files with 16 additions and 9 deletions

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.