diff --git a/pkg/build/controller/buildconfig/buildconfig_controller.go b/pkg/build/controller/buildconfig/buildconfig_controller.go index 3dac6e8be772..807377d00683 100644 --- a/pkg/build/controller/buildconfig/buildconfig_controller.go +++ b/pkg/build/controller/buildconfig/buildconfig_controller.go @@ -2,6 +2,7 @@ package controller import ( "fmt" + "strings" "time" "github.com/golang/glog" @@ -136,7 +137,11 @@ func (c *BuildConfigController) handleBuildConfig(bc *buildapi.BuildConfig) erro } else if buildgenerator.IsFatal(err) || kerrors.IsNotFound(err) || kerrors.IsBadRequest(err) || kerrors.IsForbidden(err) { instantiateErr = fmt.Errorf("gave up on Build for BuildConfig %s due to fatal error: %v", bcDesc(bc), err) utilruntime.HandleError(instantiateErr) - c.recorder.Event(bc, kapi.EventTypeWarning, "BuildConfigInstantiateFailed", instantiateErr.Error()) + // Fixes https://github.com/openshift/origin/issues/16557 + // Caused by a race condition between the ImageChangeTrigger and BuildConfigChangeTrigger + if !strings.Contains(instantiateErr.Error(), "does not match the build request LastVersion(0)") { + c.recorder.Event(bc, kapi.EventTypeWarning, "BuildConfigInstantiateFailed", instantiateErr.Error()) + } return &configControllerFatalError{err.Error()} } else { instantiateErr = fmt.Errorf("error instantiating Build from BuildConfig %s: %v", bcDesc(bc), err) diff --git a/pkg/build/generator/generator.go b/pkg/build/generator/generator.go index 9b5ec74f2c64..bd438f5ddbb4 100644 --- a/pkg/build/generator/generator.go +++ b/pkg/build/generator/generator.go @@ -318,7 +318,7 @@ func (g *BuildGenerator) instantiate(ctx apirequest.Context, request *buildapi.B return g.createBuild(ctx, newBuild) } -// checkBuildConfigLastVersion will return an error if the BuildConfig's LastVersion doesn't match the passed in lastVersion +// checkLastVersion will return an error if the BuildConfig's LastVersion doesn't match the passed in lastVersion // when lastVersion is not nil func (g *BuildGenerator) checkLastVersion(bc *buildapi.BuildConfig, lastVersion *int64) error { if lastVersion != nil && bc.Status.LastVersion != *lastVersion { diff --git a/test/cmd/newapp.sh b/test/cmd/newapp.sh index f1d23f44ea2c..f303cac0c9e8 100755 --- a/test/cmd/newapp.sh +++ b/test/cmd/newapp.sh @@ -42,6 +42,12 @@ os::cmd::expect_success 'oc delete all -l app=expose-output' os::cmd::expect_success_and_text 'oc new-app mysql --as-test' 'Application is not exposed' os::cmd::expect_success 'oc delete all -l app=mysql' +# ensure that oc new-app does not emit a BuildConfigInstantiateFailed event when creating +# a new application +os::cmd::expect_success 'oc new-app https://github.com/sclorg/ruby-ex' +os::cmd::expect_success_and_not_text 'oc describe bc/ruby-ex' 'BuildConfigInstantiateFailed' +os::cmd::expect_success 'oc delete all -l app=ruby-ex' + # test that imagestream references across imagestreams do not cause an error os::cmd::try_until_success 'oc get imagestreamtags ruby:2.3' os::cmd::expect_success 'oc create -f test/testdata/newapp/imagestream-ref.yaml'