Skip to content

Commit c337fb6

Browse files
committed
fix(builder): no build log
1 parent a44f52d commit c337fb6

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

pkg/gitreceive/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func build(
195195
}
196196

197197
options := metav1.ListOptions{
198-
LabelSelector: fmt.Sprintf("heritage=%s", newJob.Name),
198+
LabelSelector: fmt.Sprintf("job-name=%s", newJob.Name),
199199
}
200200
podList, err := kubeClient.CoreV1().Pods(newJob.Namespace).List(context.Background(), options)
201201
if err != nil {
@@ -262,7 +262,7 @@ func build(
262262
quit <- true
263263
<-quit
264264
if controller.CheckAPICompat(client, err) != nil {
265-
return fmt.Errorf("The controller returned an error when publishing the release: %s", err)
265+
return fmt.Errorf("the controller returned an error when publishing the release: %s", err)
266266
}
267267

268268
log.Info("Done, %s:v%d deployed to Workflow\n", appName, release)

pkg/gitreceive/k8s_util.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

229233
func 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

Comments
 (0)