Skip to content

Commit

Permalink
Merge pull request #1044 from dlorenc/409
Browse files Browse the repository at this point in the history
Catch a 409 when creating a bucket and continue.
  • Loading branch information
dgageot authored Sep 27, 2018
2 parents 6276334 + 989f674 commit e8257a0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/skaffold/build/gcb/cloud_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"io"
"net/http"
"time"

cstorage "cloud.google.com/go/storage"
Expand Down Expand Up @@ -253,9 +254,18 @@ func (b *Builder) createBucketIfNotExists(ctx context.Context, projectID, bucket
return errors.Wrapf(err, "getting bucket %s", bucket)
}

if err := c.Bucket(bucket).Create(ctx, projectID, &cstorage.BucketAttrs{
err = c.Bucket(bucket).Create(ctx, projectID, &cstorage.BucketAttrs{
Name: bucket,
}); err != nil {
})
if e, ok := err.(*googleapi.Error); ok {
if e.Code == http.StatusConflict {
// 409 errors are ok, there could have been a race condition or eventual consistency.
logrus.Debugf("Not creating bucket, got a 409 error indicating it already exists.")
return nil
}
}

if err != nil {
return err
}
logrus.Debugf("Created bucket %s in %s", bucket, projectID)
Expand Down

0 comments on commit e8257a0

Please sign in to comment.