Skip to content

Commit

Permalink
pkg/build: Drop references to GCSSuffix
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <[email protected]>
  • Loading branch information
justaugustus committed Nov 15, 2020
1 parent 15403b0 commit 33247d5
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 80 deletions.
5 changes: 4 additions & 1 deletion cmd/krel/cmd/ci_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func init() {
)

// Deprecated flags
// nolint: errcheck
ciBuildCmd.PersistentFlags().MarkDeprecated(
"gcs-suffix",
"`gcs-suffix` is deprecated. Please use `--gcs-root` if you need to override the default GCS root",
Expand All @@ -163,5 +164,7 @@ func init() {
}

func runCIBuild(opts *build.Options) error {
return build.NewCIInstance(opts).Build()
opts.CI = true

return build.NewInstance(opts).Build()
}
6 changes: 3 additions & 3 deletions pkg/anago/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type releaseImpl interface {
) error
ValidateImages(registry, version, buildPath string) error
PublishVersion(
buildType, version, buildDir, bucket, gcsSuffix string,
buildType, version, buildDir, bucket, gcsRoot string,
versionMarkers []string,
privateBucket, fast bool,
) error
Expand Down Expand Up @@ -174,13 +174,13 @@ func (d *defaultReleaseImpl) ValidateImages(
}

func (d *defaultReleaseImpl) PublishVersion(
buildType, version, buildDir, bucket, gcsSuffix string,
buildType, version, buildDir, bucket, gcsRoot string,
versionMarkers []string,
privateBucket, fast bool,
) error {
return release.
NewPublisher().
PublishVersion("release", version, buildDir, bucket, gcsSuffix, nil, false, false)
PublishVersion("release", version, buildDir, bucket, gcsRoot, nil, false, false)
}

func (d *DefaultRelease) Submit() error {
Expand Down
18 changes: 15 additions & 3 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Instance struct {
func NewInstance(opts *Options) *Instance {
instance := &Instance{opts}
instance.setBuildType()
instance.setGCSRoot()

return instance
}
Expand Down Expand Up @@ -121,8 +122,7 @@ func (bi *Instance) getGCSBuildPath(version string) (string, error) {

buildPath, err := gcs.GetReleasePath(
bucket,
bi.opts.BuildType,
bi.opts.GCSSuffix,
bi.opts.GCSRoot,
version,
bi.opts.Fast,
)
Expand All @@ -141,5 +141,17 @@ func (bi *Instance) setBuildType() {

bi.opts.BuildType = buildType

logrus.Infof("Build type is %s", bi.opts.BuildType)
logrus.Infof("Build type has been set to %s", bi.opts.BuildType)
}

func (bi *Instance) setGCSRoot() {
if bi.opts.GCSRoot == "" {
if bi.opts.GCSSuffix != "" {
bi.opts.GCSRoot = bi.opts.BuildType + "-" + bi.opts.GCSSuffix
} else {
bi.opts.GCSRoot = bi.opts.BuildType
}
}

logrus.Infof("GCS root has been set to %s", bi.opts.GCSRoot)
}
9 changes: 0 additions & 9 deletions pkg/build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ import (
"k8s.io/release/pkg/release"
)

// NewCIInstance can be used to create a new build `Instance` for use in CI.
func NewCIInstance(opts *Options) *Instance {
instance := NewInstance(opts)
instance.opts.CI = true
instance.setBuildType()

return instance
}

// Build starts a Kubernetes build with the options defined in the build
// `Instance`.
func (bi *Instance) Build() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (bi *Instance) Push() error {
version,
bi.opts.BuildDir,
bi.opts.Bucket,
bi.opts.GCSSuffix,
bi.opts.GCSRoot,
extraVersionMarkers,
bi.opts.PrivateBucket,
bi.opts.Fast,
Expand Down
34 changes: 16 additions & 18 deletions pkg/gcp/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,13 @@ func bucketCopy(src, dst string, opts *Options) error {
// GetReleasePath returns a GCS path to retrieve builds from or push builds to
//
// Expected destination format:
// gs://<bucket>/<buildType>[-<gcsSuffix>][/fast][/<version>]
// gs://<bucket>/<gcsRoot>[/fast][/<version>]
func GetReleasePath(
bucket, buildType, gcsSuffix, version string,
bucket, gcsRoot, version string,
fast bool) (string, error) {
gcsPath, err := getPath(
bucket,
buildType,
gcsSuffix,
gcsRoot,
version,
"release",
fast,
Expand All @@ -165,13 +164,12 @@ func GetReleasePath(
// GetMarkerPath returns a GCS path where version markers should be stored
//
// Expected destination format:
// gs://<bucket>/<buildType>[-<gcsSuffix>]
// gs://<bucket>/<gcsRoot>
func GetMarkerPath(
bucket, buildType, gcsSuffix string) (string, error) {
bucket, gcsRoot string) (string, error) {
gcsPath, err := getPath(
bucket,
buildType,
gcsSuffix,
gcsRoot,
"",
"marker",
false,
Expand All @@ -187,21 +185,18 @@ func GetMarkerPath(
// GetReleasePath returns a GCS path to retrieve builds from or push builds to
//
// Expected destination format:
// gs://<bucket>/<buildType>[-<gcsSuffix>][/fast][/<version>]
// gs://<bucket>/<gcsRoot>[/fast][/<version>]
// TODO: Support "release" buildType
func getPath(
bucket, buildType, gcsSuffix, version, pathType string,
bucket, gcsRoot, version, pathType string,
fast bool) (string, error) {
gcsPathParts := []string{}

gcsPathParts = append(gcsPathParts, bucket)

releaseRoot := buildType
if gcsSuffix != "" {
releaseRoot += "-" + gcsSuffix
if gcsRoot == "" {
return "", errors.New("GCS root must be specified")
}

gcsPathParts = append(gcsPathParts, releaseRoot)
gcsPathParts := []string{}

gcsPathParts = append(gcsPathParts, bucket, gcsRoot)

if pathType == "release" {
if fast {
Expand All @@ -211,6 +206,9 @@ func getPath(
if version != "" {
gcsPathParts = append(gcsPathParts, version)
}
} else if pathType == "marker" {
} else {
return "", errors.New("a GCS path type must be specified")
}

// Ensure any constructed GCS path is prefixed with `gs://`
Expand Down
45 changes: 13 additions & 32 deletions pkg/gcp/gcs/gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,37 @@ import (
// TODO: Add production use cases
func TestGetReleasePath(t *testing.T) {
for _, tc := range []struct {
bucket, buildType, gcsSuffix, version string
expected string
fast bool
shouldError bool
bucket, gcsRoot, version string
expected string
fast bool
shouldError bool
}{
{ // default CI build
bucket: "k8s-release-dev",
buildType: "ci",
gcsRoot: "ci",
expected: "gs://k8s-release-dev/ci",
shouldError: false,
},
{ // fast CI build
bucket: "k8s-release-dev",
buildType: "ci",
gcsSuffix: "",
gcsRoot: "ci",
version: "",
fast: true,
expected: "gs://k8s-release-dev/ci/fast",
shouldError: false,
},
{ // has version
bucket: "k8s-release-dev",
buildType: "ci",
gcsSuffix: "",
gcsRoot: "ci",
version: "42",
fast: true,
expected: "gs://k8s-release-dev/ci/fast/42",
shouldError: false,
},
{ // has GCS suffix
bucket: "k8s-release-dev",
buildType: "ci",
gcsSuffix: "suffix",
fast: true,
expected: "gs://k8s-release-dev/ci-suffix/fast",
shouldError: false,
},
} {
actual, err := gcs.GetReleasePath(
tc.bucket,
tc.buildType,
tc.gcsSuffix,
tc.gcsRoot,
tc.version,
tc.fast,
)
Expand All @@ -86,28 +75,20 @@ func TestGetReleasePath(t *testing.T) {
// TODO: Add production use cases
func TestGetMarkerPath(t *testing.T) {
for _, tc := range []struct {
bucket, buildType, gcsSuffix string
expected string
shouldError bool
bucket, gcsRoot string
expected string
shouldError bool
}{
{ // default CI build
bucket: "k8s-release-dev",
buildType: "ci",
gcsRoot: "ci",
expected: "gs://k8s-release-dev/ci",
shouldError: false,
},
{ // has GCS suffix
bucket: "k8s-release-dev",
buildType: "ci",
gcsSuffix: "suffix",
expected: "gs://k8s-release-dev/ci-suffix",
shouldError: false,
},
} {
actual, err := gcs.GetMarkerPath(
tc.bucket,
tc.buildType,
tc.gcsSuffix,
tc.gcsRoot,
)

require.Equal(t, tc.expected, actual)
Expand Down
13 changes: 5 additions & 8 deletions pkg/release/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,14 @@ func (*defaultPublisher) GetURLResponse(url string) (string, error) {
// version - The version
// buildDir - build output directory
// bucket - GCS bucket
// gcsSuffix - appended to the buildType to construct a new top-level
// destination
// gcsRoot - The top-level GCS directory builds will be released to
//
// Expected destination format:
// gs://<bucket>/<buildType>[-<gcsSuffix>][/fast]/<version>
// gs://<bucket>/<gcsRoot>[/fast]/<version>
//
// was releaselib.sh: release::gcs::publish_version
func (p *Publisher) PublishVersion(
buildType, version, buildDir, bucket, gcsSuffix string,
buildType, version, buildDir, bucket, gcsRoot string,
extraVersionMarkers []string,
privateBucket, fast bool,
) error {
Expand All @@ -107,17 +106,15 @@ func (p *Publisher) PublishVersion(

markerPath, markerPathErr := gcs.GetMarkerPath(
bucket,
buildType,
gcsSuffix,
gcsRoot,
)
if markerPathErr != nil {
return errors.Wrap(markerPathErr, "get version marker path")
}

releasePath, releasePathErr := gcs.GetReleasePath(
bucket,
buildType,
gcsSuffix,
gcsRoot,
version,
fast,
)
Expand Down
Loading

0 comments on commit 33247d5

Please sign in to comment.