Skip to content

Commit

Permalink
Merge pull request #13910 from jim-minter/issue13694
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored May 11, 2017
2 parents 012de50 + 84906c4 commit f24a57f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/build/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/openshift/origin/pkg/util/namer"
)

const conflictRetries = 3

// GeneratorFatalError represents a fatal error while generating a build.
// An operation that fails because of a fatal error should not be retried.
type GeneratorFatalError struct {
Expand Down Expand Up @@ -248,6 +250,21 @@ func updateBuildArgs(oldArgs *[]kapi.EnvVar, newArgs []kapi.EnvVar) []kapi.EnvVa

// Instantiate returns a new Build object based on a BuildRequest object
func (g *BuildGenerator) Instantiate(ctx apirequest.Context, request *buildapi.BuildRequest) (*buildapi.Build, error) {
var build *buildapi.Build
var err error

for i := 0; i < conflictRetries; i++ {
build, err = g.instantiate(ctx, request)
if err == nil || !errors.IsConflict(err) {
break
}
glog.V(4).Infof("instantiate returned conflict, try %d/%d", i+1, conflictRetries)
}

return build, err
}

func (g *BuildGenerator) instantiate(ctx apirequest.Context, request *buildapi.BuildRequest) (*buildapi.Build, error) {
glog.V(4).Infof("Generating Build from %s", describeBuildRequest(request))
bc, err := g.Client.GetBuildConfig(ctx, request.Name, &metav1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -374,6 +391,21 @@ func (g *BuildGenerator) updateImageTriggers(ctx apirequest.Context, bc *buildap

// Clone returns clone of a Build
func (g *BuildGenerator) Clone(ctx apirequest.Context, request *buildapi.BuildRequest) (*buildapi.Build, error) {
var build *buildapi.Build
var err error

for i := 0; i < conflictRetries; i++ {
build, err = g.clone(ctx, request)
if err == nil || !errors.IsConflict(err) {
break
}
glog.V(4).Infof("clone returned conflict, try %d/%d", i+1, conflictRetries)
}

return build, err
}

func (g *BuildGenerator) clone(ctx apirequest.Context, request *buildapi.BuildRequest) (*buildapi.Build, error) {
glog.V(4).Infof("Generating build from build %s/%s", request.Namespace, request.Name)
build, err := g.Client.GetBuild(ctx, request.Name, &metav1.GetOptions{})
if err != nil {
Expand Down

0 comments on commit f24a57f

Please sign in to comment.