@@ -96,6 +96,7 @@ func buildJob(
9696 ObjectMeta : metav1.ObjectMeta {
9797 Labels : map [string ]string {
9898 "app" : builderName ,
99+ "job-name" : name ,
99100 "heritage" : "drycc" ,
100101 },
101102 },
@@ -114,6 +115,7 @@ func buildJob(
114115 Namespace : namespace ,
115116 Labels : map [string ]string {
116117 "app" : builderName ,
118+ "job-name" : name ,
117119 "heritage" : "drycc" ,
118120 },
119121 },
@@ -169,7 +171,7 @@ func addEnvToJob(job batchv1.Job, key, value string) {
169171}
170172
171173// waitForPod waits for a pod in state running, succeeded or failed
172- func waitForPod (pw * k8s.PodWatcher , podName string , ticker , interval , timeout time.Duration ) error {
174+ func waitForPod (pw * k8s.PodWatcher , jobName string , ticker , interval , timeout time.Duration ) error {
173175 condition := func (pod * corev1.Pod ) (bool , error ) {
174176 if pod .Status .Phase == corev1 .PodRunning {
175177 return true , nil
@@ -178,20 +180,20 @@ func waitForPod(pw *k8s.PodWatcher, podName string, ticker, interval, timeout ti
178180 return true , nil
179181 }
180182 if pod .Status .Phase == corev1 .PodFailed {
181- return true , fmt .Errorf ("Giving up; pod went into failed status: \n [%s]:%s" , pod .Status .Reason , pod .Status .Message )
183+ return true , fmt .Errorf ("giving up; pod went into failed status: \n [%s]:%s" , pod .Status .Reason , pod .Status .Message )
182184 }
183185 return false , nil
184186 }
185187
186188 quit := progress ("..." , ticker )
187- err := waitForPodCondition (pw , podName , condition , interval , timeout )
189+ err := waitForPodCondition (pw , jobName , condition , interval , timeout )
188190 quit <- true
189191 <- quit
190192 return err
191193}
192194
193195// waitForPodEnd waits for a pod in state succeeded or failed
194- func waitForPodEnd (pw * k8s.PodWatcher , podName string , interval , timeout time.Duration ) error {
196+ func waitForPodEnd (pw * k8s.PodWatcher , jobName string , interval , timeout time.Duration ) error {
195197 condition := func (pod * corev1.Pod ) (bool , error ) {
196198 if pod .Status .Phase == corev1 .PodSucceeded {
197199 return true , nil
@@ -202,40 +204,42 @@ func waitForPodEnd(pw *k8s.PodWatcher, podName string, interval, timeout time.Du
202204 return false , nil
203205 }
204206
205- return waitForPodCondition (pw , podName , condition , interval , timeout )
207+ return waitForPodCondition (pw , jobName , condition , interval , timeout )
206208}
207209
208210// waitForPodCondition waits for a pod in state defined by a condition (func)
209- func waitForPodCondition (pw * k8s.PodWatcher , podName string , condition func (pod * corev1.Pod ) (bool , error ),
211+ func waitForPodCondition (pw * k8s.PodWatcher , jobName string , condition func (pod * corev1.Pod ) (bool , error ),
210212 interval , timeout time.Duration ) error {
211- return wait .PollImmediate (interval , timeout , func () (bool , error ) {
212- pods , err := pw .Store .List (labels.Set {"heritage" : podName }.AsSelector ())
213+ return wait .PollUntilContextTimeout (context .Background (), interval , timeout , true , func (ctx context.Context ) (done bool , err error ) {
214+ selector := labels.Set {
215+ "job-name" : jobName ,
216+ "heritage" : "drycc" ,
217+ }.AsSelector ()
218+ pods , err := pw .Store .List (selector )
213219 if err != nil || len (pods ) == 0 {
214220 return false , nil
215221 }
216-
217- done , err := condition (pods [0 ])
222+ done , err = condition (pods [0 ])
218223 if err != nil {
219224 return false , err
220225 }
221226 if done {
222227 return true , nil
223228 }
224-
225229 return false , nil
226230 })
227231}
228232
229233func progress (msg string , interval time.Duration ) chan bool {
230- tick := time .Tick (interval )
234+ tick := time .NewTicker (interval )
231235 quit := make (chan bool )
232236 go func () {
233237 for {
234238 select {
235239 case <- quit :
236240 close (quit )
237241 return
238- case <- tick :
242+ case <- tick . C :
239243 fmt .Println (msg )
240244 }
241245 }
0 commit comments