Skip to content

Commit ba73984

Browse files
committed
Add 'MissingSecret' reason for pending builds
1 parent 4cbd7bd commit ba73984

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

pkg/build/api/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ const (
259259
// StatusReasonExceededRetryTimeout is an error condition when the build has
260260
// not completed and retrying the build times out.
261261
StatusReasonExceededRetryTimeout = "ExceededRetryTimeout"
262+
263+
// StatusReasonMissingPushSecret indicates that the build is missing required
264+
// secret for pushing the output image.
265+
// The build will stay in the pending state until the secret is created, or the build times out.
266+
StatusReasonMissingPushSecret = "MissingPushSecret"
262267
)
263268

264269
// BuildSource is the input used for the build.

pkg/build/controller/controller.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"k8s.io/kubernetes/pkg/api/unversioned"
1111
"k8s.io/kubernetes/pkg/client/cache"
1212
"k8s.io/kubernetes/pkg/client/record"
13+
kclient "k8s.io/kubernetes/pkg/client/unversioned"
1314

1415
buildapi "github.com/openshift/origin/pkg/build/api"
1516
buildclient "github.com/openshift/origin/pkg/build/client"
@@ -266,6 +267,7 @@ func (bc *BuildController) resolveOutputDockerImageReference(build *buildapi.Bui
266267
type BuildPodController struct {
267268
BuildStore cache.Store
268269
BuildUpdater buildclient.BuildUpdater
270+
SecretClient kclient.SecretsNamespacer
269271
PodManager podManager
270272
}
271273

@@ -284,13 +286,26 @@ func (bc *BuildPodController) HandlePod(pod *kapi.Pod) error {
284286
build := obj.(*buildapi.Build)
285287

286288
nextStatus := build.Status.Phase
289+
currentReason := build.Status.Reason
290+
287291
switch pod.Status.Phase {
288292
case kapi.PodRunning:
289293
// The pod's still running
294+
build.Status.Reason = ""
290295
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+
}
291305
case kapi.PodSucceeded:
292306
// Check the exit codes of all the containers in the pod
293307
nextStatus = buildapi.BuildPhaseComplete
308+
build.Status.Reason = ""
294309
if len(pod.Status.ContainerStatuses) == 0 {
295310
// no containers in the pod means something went badly wrong, so the build
296311
// should be failed.
@@ -305,13 +320,19 @@ func (bc *BuildPodController) HandlePod(pod *kapi.Pod) error {
305320
}
306321
}
307322
case kapi.PodFailed:
323+
build.Status.Reason = ""
308324
nextStatus = buildapi.BuildPhaseFailed
309325
}
310326

327+
// Update the build object when it progress to a next state or the reason for
328+
// the current state changed.
311329
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)
313335
build.Status.Phase = nextStatus
314-
build.Status.Reason = ""
315336
build.Status.Message = ""
316337
if buildutil.IsBuildComplete(build) {
317338
now := unversioned.Now()

pkg/build/controller/factory/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func (factory *BuildPodControllerFactory) Create() controller.RunnableController
197197
buildPodController := &buildcontroller.BuildPodController{
198198
BuildStore: factory.buildStore,
199199
BuildUpdater: factory.BuildUpdater,
200+
SecretClient: factory.KubeClient,
200201
PodManager: client,
201202
}
202203

0 commit comments

Comments
 (0)