@@ -147,6 +147,37 @@ func addEnvToPod(pod api.Pod, key, value string) {
147147
148148// waitForPod waits for a pod in state running or failed
149149func waitForPod (c * client.Client , ns , podName string , interval , timeout time.Duration ) error {
150+ condition := func (pod * api.Pod ) (bool , error ) {
151+ if pod .Status .Phase == api .PodRunning {
152+ return true , nil
153+ }
154+ if pod .Status .Phase == api .PodFailed {
155+ return true , fmt .Errorf ("Giving up; pod went into failed status: \n %s" , fmt .Sprintf ("%#v" , pod ))
156+ }
157+ return false , nil
158+ }
159+
160+ return waitForPodCondition (c , ns , podName , condition , interval , timeout )
161+ }
162+
163+ // waitForPodEnd waits for a pod in state succeeded or failed
164+ func waitForPodEnd (c * client.Client , ns , podName string , interval , timeout time.Duration ) error {
165+ condition := func (pod * api.Pod ) (bool , error ) {
166+ if pod .Status .Phase == api .PodSucceeded {
167+ return true , nil
168+ }
169+ if pod .Status .Phase == api .PodFailed {
170+ return true , nil
171+ }
172+ return false , nil
173+ }
174+
175+ return waitForPodCondition (c , ns , podName , condition , interval , timeout )
176+ }
177+
178+ // waitForPodCondition waits for a pod in state defined by a condition (func)
179+ func waitForPodCondition (c * client.Client , ns , podName string , condition func (pod * api.Pod ) (bool , error ),
180+ interval , timeout time.Duration ) error {
150181 return wait .PollImmediate (interval , timeout , func () (bool , error ) {
151182 pod , err := c .Pods (ns ).Get (podName )
152183 if err != nil {
@@ -155,16 +186,6 @@ func waitForPod(c *client.Client, ns, podName string, interval, timeout time.Dur
155186 }
156187 }
157188
158- condition := func (pod * api.Pod ) (bool , error ) {
159- if pod .Status .Phase == api .PodRunning {
160- return true , nil
161- }
162- if pod .Status .Phase == api .PodFailed {
163- return true , fmt .Errorf ("Giving up; pod went into failed status: \n %s" , fmt .Sprintf ("%#v" , pod ))
164- }
165- return false , nil
166- }
167-
168189 done , err := condition (pod )
169190 if done {
170191 return true , nil
0 commit comments