Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to delete source archive should not fail GCB builds #5891

Merged
merged 2 commits into from
May 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pkg/skaffold/build/gcb/cloud_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

cstorage "cloud.google.com/go/storage"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
"google.golang.org/api/cloudbuild/v1"
"google.golang.org/api/googleapi"
Expand All @@ -40,7 +41,6 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/gcp"
latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/sources"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

// Build builds a list of artifacts with Google Cloud Build.
Expand Down Expand Up @@ -85,7 +85,7 @@ func (b *Builder) buildArtifactWithCloudBuild(ctx context.Context, out io.Writer
}

cbBucket := fmt.Sprintf("%s%s", projectID, constants.GCSBucketSuffix)
buildObject := fmt.Sprintf("source/%s-%s.tar.gz", projectID, util.RandomID())
buildObject := fmt.Sprintf("source/%s-%s.tar.gz", projectID, uuid.New().String())

if err := b.createBucketIfNotExists(ctx, c, projectID, cbBucket); err != nil {
return "", fmt.Errorf("creating bucket if not exists: %w", err)
Expand Down Expand Up @@ -113,7 +113,7 @@ func (b *Builder) buildArtifactWithCloudBuild(ctx context.Context, out io.Writer
}

if err := sources.UploadToGCS(ctx, c, artifact, cbBucket, buildObject, dependencies); err != nil {
return "", fmt.Errorf("uploading source tarball: %w", err)
return "", fmt.Errorf("uploading source archive: %w", err)
}

buildSpec, err := b.buildSpec(artifact, tag, cbBucket, buildObject)
Expand Down Expand Up @@ -193,9 +193,10 @@ watch:
}

if err := c.Bucket(cbBucket).Object(buildObject).Delete(ctx); err != nil {
return "", fmt.Errorf("cleaning up source tar after build: %w", err)
logrus.Warnf("Unable to deleting source archive after build: %q: %v", buildObject, err)
} else {
logrus.Infof("Deleted source archive %s", buildObject)
}
logrus.Infof("Deleted object %s", buildObject)

return build.TagWithDigest(tag, digest), nil
}
Expand Down