Commit b840f039 authored by k8s-merge-robot's avatar k8s-merge-robot Committed by GitHub

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
parents 0699b4d4 e7095998
...@@ -37,25 +37,31 @@ func (f *Framework) PodClient() unversioned.PodInterface { ...@@ -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. // Create a new pod according to the framework specifications, and wait for it to start.
func (f *Framework) CreatePod(pod *api.Pod) { // Returns the server's representation of the pod.
f.CreatePodAsync(pod) func (f *Framework) CreatePod(pod *api.Pod) *api.Pod {
ExpectNoError(f.WaitForPodRunning(pod.Name)) 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). // 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) f.MungePodSpec(pod)
_, err := f.PodClient().Create(pod) p, err := f.PodClient().Create(pod)
ExpectNoError(err, "Error creating Pod") ExpectNoError(err, "Error creating Pod")
return p
} }
// Batch version of CreatePod. All pods are created before waiting. // Batch version of CreatePod. All pods are created before waiting.
func (f *Framework) CreatePods(pods []*api.Pod) { // Returns a slice, in the same order as pods, containing the server's representations of the pods.
for _, pod := range pods { func (f *Framework) CreatePods(pods []*api.Pod) []*api.Pod {
f.CreatePodAsync(pod) ps := make([]*api.Pod, len(pods))
for i, pod := range pods {
ps[i] = f.CreatePodAsync(pod)
} }
var wg sync.WaitGroup var wg sync.WaitGroup
for _, pod := range pods { for _, pod := range ps {
wg.Add(1) wg.Add(1)
podName := pod.Name podName := pod.Name
go func() { go func() {
...@@ -64,6 +70,7 @@ func (f *Framework) CreatePods(pods []*api.Pod) { ...@@ -64,6 +70,7 @@ func (f *Framework) CreatePods(pods []*api.Pod) {
}() }()
} }
wg.Wait() wg.Wait()
return ps
} }
// Apply test-suite specific transformations to the pod spec. // Apply test-suite specific transformations to the pod spec.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment