@@ -10,6 +10,7 @@ import (
10
10
"k8s.io/kubernetes/pkg/api/unversioned"
11
11
"k8s.io/kubernetes/pkg/client/cache"
12
12
"k8s.io/kubernetes/pkg/client/record"
13
+ kclient "k8s.io/kubernetes/pkg/client/unversioned"
13
14
14
15
buildapi "github.com/openshift/origin/pkg/build/api"
15
16
buildclient "github.com/openshift/origin/pkg/build/client"
@@ -266,6 +267,7 @@ func (bc *BuildController) resolveOutputDockerImageReference(build *buildapi.Bui
266
267
type BuildPodController struct {
267
268
BuildStore cache.Store
268
269
BuildUpdater buildclient.BuildUpdater
270
+ SecretClient kclient.SecretsNamespacer
269
271
PodManager podManager
270
272
}
271
273
@@ -284,13 +286,26 @@ func (bc *BuildPodController) HandlePod(pod *kapi.Pod) error {
284
286
build := obj .(* buildapi.Build )
285
287
286
288
nextStatus := build .Status .Phase
289
+ currentReason := build .Status .Reason
290
+
287
291
switch pod .Status .Phase {
288
292
case kapi .PodRunning :
289
293
// The pod's still running
294
+ build .Status .Reason = ""
290
295
nextStatus = buildapi .BuildPhaseRunning
296
+ case kapi .PodPending :
297
+ build .Status .Reason = ""
298
+ nextStatus = buildapi .BuildPhasePending
299
+ if secret := build .Spec .Output .PushSecret ; secret != nil && currentReason != buildapi .StatusReasonMissingPushSecret {
300
+ if _ , err := bc .SecretClient .Secrets (build .Namespace ).Get (secret .Name ); err != nil && errors .IsNotFound (err ) {
301
+ build .Status .Reason = buildapi .StatusReasonMissingPushSecret
302
+ glog .V (4 ).Infof ("Setting reason for pending build to %q due to missing secret %s/%s" , build .Status .Reason , build .Namespace , secret .Name )
303
+ }
304
+ }
291
305
case kapi .PodSucceeded :
292
306
// Check the exit codes of all the containers in the pod
293
307
nextStatus = buildapi .BuildPhaseComplete
308
+ build .Status .Reason = ""
294
309
if len (pod .Status .ContainerStatuses ) == 0 {
295
310
// no containers in the pod means something went badly wrong, so the build
296
311
// should be failed.
@@ -305,13 +320,19 @@ func (bc *BuildPodController) HandlePod(pod *kapi.Pod) error {
305
320
}
306
321
}
307
322
case kapi .PodFailed :
323
+ build .Status .Reason = ""
308
324
nextStatus = buildapi .BuildPhaseFailed
309
325
}
310
326
327
+ // Update the build object when it progress to a next state or the reason for
328
+ // the current state changed.
311
329
if build .Status .Phase != nextStatus && ! buildutil .IsBuildComplete (build ) {
312
- glog .V (4 ).Infof ("Updating build %s/%s status %s -> %s" , build .Namespace , build .Name , build .Status .Phase , nextStatus )
330
+ reason := ""
331
+ if len (build .Status .Reason ) > 0 {
332
+ reason = " (" + string (build .Status .Reason ) + ")"
333
+ }
334
+ glog .V (4 ).Infof ("Updating build %s/%s status %s -> %s%s" , build .Namespace , build .Name , build .Status .Phase , nextStatus , reason )
313
335
build .Status .Phase = nextStatus
314
- build .Status .Reason = ""
315
336
build .Status .Message = ""
316
337
if buildutil .IsBuildComplete (build ) {
317
338
now := unversioned .Now ()
0 commit comments