@@ -213,6 +213,7 @@ func NewBuildController(params *BuildControllerParams) *BuildController {
213
213
c .buildInformer .AddEventHandler (cache.ResourceEventHandlerFuncs {
214
214
AddFunc : c .buildAdded ,
215
215
UpdateFunc : c .buildUpdated ,
216
+ DeleteFunc : c .buildDeleted ,
216
217
})
217
218
params .ImageStreamInformer .Informer ().AddEventHandler (cache.ResourceEventHandlerFuncs {
218
219
AddFunc : c .imageStreamAdded ,
@@ -1067,10 +1068,14 @@ func (bc *BuildController) handleBuildConfig(bcNamespace string, bcName string)
1067
1068
return err
1068
1069
}
1069
1070
glog .V (5 ).Infof ("Build config %s/%s: has %d next builds, is running builds: %v" , bcNamespace , bcName , len (nextBuilds ), hasRunningBuilds )
1070
- if len ( nextBuilds ) == 0 && hasRunningBuilds {
1071
+ if hasRunningBuilds {
1071
1072
glog .V (4 ).Infof ("Build config %s/%s has running builds, will retry" , bcNamespace , bcName )
1072
1073
return fmt .Errorf ("build config %s/%s has running builds and cannot run more builds" , bcNamespace , bcName )
1073
1074
}
1075
+ if len (nextBuilds ) == 0 {
1076
+ glog .V (4 ).Infof ("Build config %s/%s has no builds to run next, will retry" , bcNamespace , bcName )
1077
+ return fmt .Errorf ("build config %s/%s has no builds to run next" , bcNamespace , bcName )
1078
+ }
1074
1079
1075
1080
// Enqueue any builds to build next
1076
1081
for _ , build := range nextBuilds {
@@ -1174,6 +1179,29 @@ func (bc *BuildController) buildUpdated(old, cur interface{}) {
1174
1179
bc .enqueueBuild (build )
1175
1180
}
1176
1181
1182
+ // buildDeleted is called by the build informer event handler whenever a build
1183
+ // is deleted
1184
+ func (bc * BuildController ) buildDeleted (obj interface {}) {
1185
+ build , ok := obj .(* buildapi.Build )
1186
+ if ! ok {
1187
+ tombstone , ok := obj .(cache.DeletedFinalStateUnknown )
1188
+ if ! ok {
1189
+ utilruntime .HandleError (fmt .Errorf ("couldn't get object from tombstone: %+v" , obj ))
1190
+ return
1191
+ }
1192
+ build , ok = tombstone .Obj .(* buildapi.Build )
1193
+ if ! ok {
1194
+ utilruntime .HandleError (fmt .Errorf ("tombstone contained object that is not a pod: %+v" , obj ))
1195
+ return
1196
+ }
1197
+ }
1198
+ // If the build was not in a complete state, poke the buildconfig to run the next build
1199
+ if ! buildutil .IsBuildComplete (build ) {
1200
+ bcName := buildutil .ConfigNameForBuild (build )
1201
+ bc .enqueueBuildConfig (build .Namespace , bcName )
1202
+ }
1203
+ }
1204
+
1177
1205
// enqueueBuild adds the given build to the buildQueue.
1178
1206
func (bc * BuildController ) enqueueBuild (build * buildapi.Build ) {
1179
1207
key := resourceName (build .Namespace , build .Name )
0 commit comments