Skip to content

Commit

Permalink
[krel] gcbmgr: Dynamically retrieve build version from CI markers
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
  • Loading branch information
justaugustus committed Feb 20, 2020
1 parent 3e52346 commit f2cc7cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
28 changes: 18 additions & 10 deletions cmd/krel/cmd/gcbmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func init() {
gcbmgrCmd.PersistentFlags().StringVar(
&gcbmgrOpts.buildVersion,
"build-version",
"FAKE+BUILD+POINT",
"",
"Build version",
)

Expand Down Expand Up @@ -308,25 +308,33 @@ func setGCBSubstitutions(o *gcbmgrOptions) (map[string]string, error) {
gcbSubs["RC"] = ""
}

branch := o.branch
if branch == "" {
return gcbSubs, errors.New("Release branch must be set to continue")
}

gcbSubs["RELEASE_BRANCH"] = branch

// TODO: Remove once we remove support for --built-at-head.
gcbSubs["BUILD_AT_HEAD"] = ""

buildpoint := o.buildVersion
buildVersion := o.buildVersion
if buildVersion == "" {
var versionErr error
buildVersion, versionErr = release.GetCIKubeVersion(o.branch)
if versionErr != nil {
return gcbSubs, versionErr
}
}

buildpoint := buildVersion
buildpoint = strings.ReplaceAll(buildpoint, "+", "-")
gcbSubs["BUILD_POINT"] = buildpoint

// TODO: Add conditionals for find_green_build
buildVersion := o.buildVersion
buildVersion = fmt.Sprintf("--buildversion=%s", buildVersion)
gcbSubs["BUILDVERSION"] = buildVersion

branch := o.branch
if branch == "" {
return gcbSubs, errors.New("Release branch must be set to continue")
}

gcbSubs["RELEASE_BRANCH"] = branch

kubecrossBranches := []string{
branch,
"master",
Expand Down
10 changes: 1 addition & 9 deletions cmd/krel/cmd/gcbmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
gcpUser: "test-user",
},
expected: map[string]string{
"BUILDVERSION": "--buildversion=",
"BUILD_AT_HEAD": "",
"BUILD_POINT": "",
"OFFICIAL": "",
"OFFICIAL_TAG": "",
"RC": "",
Expand All @@ -131,9 +129,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
gcpUser: "test-user",
},
expected: map[string]string{
"BUILDVERSION": "--buildversion=",
"BUILD_AT_HEAD": "",
"BUILD_POINT": "",
"OFFICIAL": "",
"OFFICIAL_TAG": "",
"RC": "--rc",
Expand All @@ -152,9 +148,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
gcpUser: "test-user",
},
expected: map[string]string{
"BUILDVERSION": "--buildversion=",
"BUILD_AT_HEAD": "",
"BUILD_POINT": "",
"OFFICIAL": "--official",
"OFFICIAL_TAG": "official",
"RC": "",
Expand All @@ -176,9 +170,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
toolRepo: "best-tools",
toolBranch: "tool-branch",
expected: map[string]string{
"BUILDVERSION": "--buildversion=",
"BUILD_AT_HEAD": "",
"BUILD_POINT": "",
"OFFICIAL": "--official",
"OFFICIAL_TAG": "official",
"RC": "",
Expand Down Expand Up @@ -239,7 +231,7 @@ func dropDynamicSubstitutions(orig map[string]string) (result map[string]string)
result = orig

for k := range result {
if k == "GCP_USER_TAG" || k == "KUBE_CROSS_VERSION" {
if k == "BUILDVERSION" || k == "BUILD_POINT" || k == "GCP_USER_TAG" || k == "KUBE_CROSS_VERSION" {
delete(result, k)
}
}
Expand Down

0 comments on commit f2cc7cd

Please sign in to comment.