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

Add FORCE_BUILD_KREL GCB env var to build krel from sources #3760

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions gcb/fast-forward/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ steps:
- "TOOL_ORG=${_TOOL_ORG}"
- "TOOL_REPO=${_TOOL_REPO}"
- "TOOL_REF=${_TOOL_REF}"
- "FORCE_BUILD_KREL=${_FORCE_BUILD_KREL}"
args:
- ./hack/get-krel

Expand Down
1 change: 1 addition & 0 deletions gcb/obs-release/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ steps:
- "TOOL_ORG=${_TOOL_ORG}"
- "TOOL_REPO=${_TOOL_REPO}"
- "TOOL_REF=${_TOOL_REF}"
- "FORCE_BUILD_KREL=${_FORCE_BUILD_KREL}"
args:
- ./hack/get-krel

Expand Down
1 change: 1 addition & 0 deletions gcb/obs-stage/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ steps:
- "TOOL_ORG=${_TOOL_ORG}"
- "TOOL_REPO=${_TOOL_REPO}"
- "TOOL_REF=${_TOOL_REF}"
- "FORCE_BUILD_KREL=${_FORCE_BUILD_KREL}"
args:
- ./hack/get-krel

Expand Down
1 change: 1 addition & 0 deletions gcb/release/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ steps:
- "TOOL_ORG=${_TOOL_ORG}"
- "TOOL_REPO=${_TOOL_REPO}"
- "TOOL_REF=${_TOOL_REF}"
- "FORCE_BUILD_KREL=${_FORCE_BUILD_KREL}"
args:
- ./hack/get-krel

Expand Down
1 change: 1 addition & 0 deletions gcb/stage/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ steps:
- "TOOL_ORG=${_TOOL_ORG}"
- "TOOL_REPO=${_TOOL_REPO}"
- "TOOL_REF=${_TOOL_REF}"
- "FORCE_BUILD_KREL=${_FORCE_BUILD_KREL}"
args:
- ./hack/get-krel

Expand Down
10 changes: 9 additions & 1 deletion hack/get-krel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
set -o errexit
set -o nounset
set -o pipefail
set -x

curl_retry() {
curl -sSfL --retry 5 --retry-delay 3 "$@"
Expand All @@ -29,11 +30,18 @@ DEFAULT_TOOL_REF=master
TOOL_ORG=${TOOL_ORG:-${DEFAULT_TOOL_ORG}}
TOOL_REPO=${TOOL_REPO:-${DEFAULT_TOOL_REPO}}
TOOL_REF=${TOOL_REF:-${DEFAULT_TOOL_REF}}

FORCE_BUILD_KREL=${FORCE_BUILD_KREL:-false}

KREL_OUTPUT_PATH=${KREL_OUTPUT_PATH:-bin/krel}
echo "Using output path: $KREL_OUTPUT_PATH"
mkdir -p "$(dirname "$KREL_OUTPUT_PATH")"

if [[ "$TOOL_ORG" == "$DEFAULT_TOOL_ORG" && "$TOOL_REPO" == "$DEFAULT_TOOL_REPO" && "$TOOL_REF" == "$DEFAULT_TOOL_REF" ]]; then
if [[ "$FORCE_BUILD_KREL" == false &&
"$TOOL_ORG" == "$DEFAULT_TOOL_ORG" &&
"$TOOL_REPO" == "$DEFAULT_TOOL_REPO" &&
"$TOOL_REF" == "$DEFAULT_TOOL_REF" ]]; then

LATEST_RELEASE=$(curl_retry https://api.github.com/repos/kubernetes/release/releases/latest | jq -r .tag_name)
echo "Using krel release: $LATEST_RELEASE"

Expand Down
6 changes: 4 additions & 2 deletions pkg/gcp/gcb/gcb.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func (g *GCB) Submit() error {
toolOrg := release.GetToolOrg()
toolRepo := release.GetToolRepo()
toolRef := release.GetToolRef()
forceBuildKrel := release.GetForceBuildKrel()

if err := gcli.PreCheck(); err != nil {
return fmt.Errorf("pre-checking for GCP package usage: %w", err)
Expand Down Expand Up @@ -289,7 +290,7 @@ func (g *GCB) Submit() error {
gcsBucket = strings.ReplaceAll(gcsBucket, release.TestBucket, release.ProductionBucket)
}

gcbSubs, gcbSubsErr := g.SetGCBSubstitutions(toolOrg, toolRepo, toolRef, gcsBucket)
gcbSubs, gcbSubsErr := g.SetGCBSubstitutions(toolOrg, toolRepo, toolRef, gcsBucket, forceBuildKrel)
if gcbSubs == nil || gcbSubsErr != nil {
return gcbSubsErr
}
Expand Down Expand Up @@ -351,12 +352,13 @@ func (g *GCB) Submit() error {

// SetGCBSubstitutions takes a set of `Options` and returns a map of GCB
// substitutions.
func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef, gcsBucket string) (map[string]string, error) {
func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef, gcsBucket, forceBuildKrel string) (map[string]string, error) {
gcbSubs := map[string]string{}

gcbSubs["TOOL_ORG"] = toolOrg
gcbSubs["TOOL_REPO"] = toolRepo
gcbSubs["TOOL_REF"] = toolRef
gcbSubs["FORCE_BUILD_KREL"] = forceBuildKrel

gcbSubs["K8S_ORG"] = release.GetK8sOrg()
if g.options.CustomK8sOrg != "" {
Expand Down
64 changes: 38 additions & 26 deletions pkg/gcp/gcb/gcb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ func TestSubmitGcbFailure(t *testing.T) {

func TestSetGCBSubstitutionsSuccess(t *testing.T) {
testcases := []struct {
name string
gcbOpts *gcb.Options
toolOrg string
toolRepo string
toolRef string
expected map[string]string
repoMock gcb.Repository
versionMock gcb.Version
releaseMock gcb.Release
name string
gcbOpts *gcb.Options
toolOrg string
toolRepo string
toolRef string
forceBuildKrel string
expected map[string]string
repoMock gcb.Repository
versionMock gcb.Version
releaseMock gcb.Release
}{
{
name: "main branch alpha - stage",
Expand All @@ -183,6 +184,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"TOOL_ORG": "",
"TOOL_REPO": "",
"TOOL_REF": "",
"FORCE_BUILD_KREL": "",
"TYPE": release.ReleaseTypeAlpha,
"TYPE_TAG": release.ReleaseTypeAlpha,
"MAJOR_VERSION_TAG": "1",
Expand Down Expand Up @@ -211,6 +213,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"TOOL_ORG": "",
"TOOL_REPO": "",
"TOOL_REF": "",
"FORCE_BUILD_KREL": "",
"TYPE": release.ReleaseTypeBeta,
"TYPE_TAG": release.ReleaseTypeBeta,
"MAJOR_VERSION_TAG": "1",
Expand Down Expand Up @@ -239,6 +242,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"TOOL_ORG": "",
"TOOL_REPO": "",
"TOOL_REF": "",
"FORCE_BUILD_KREL": "",
"TYPE": release.ReleaseTypeRC,
"TYPE_TAG": release.ReleaseTypeRC,
"MAJOR_VERSION_TAG": "1",
Expand Down Expand Up @@ -266,6 +270,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"TOOL_ORG": "",
"TOOL_REPO": "",
"TOOL_REF": "",
"FORCE_BUILD_KREL": "",
"TYPE": release.ReleaseTypeOfficial,
"TYPE_TAG": release.ReleaseTypeOfficial,
"MAJOR_VERSION_TAG": "1",
Expand All @@ -285,19 +290,21 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
ReleaseType: release.ReleaseTypeOfficial,
GcpUser: "test-user",
},
repoMock: mockRepo(),
versionMock: mockVersion("v1.16.0"),
releaseMock: mockRelease("v1.16.0"),
toolOrg: "honk",
toolRepo: "best-tools",
toolRef: "tool-branch",
repoMock: mockRepo(),
versionMock: mockVersion("v1.16.0"),
releaseMock: mockRelease("v1.16.0"),
toolOrg: "honk",
toolRepo: "best-tools",
toolRef: "tool-branch",
forceBuildKrel: "true",
expected: map[string]string{
"RELEASE_BRANCH": "release-1.16",
"TOOL_ORG": "honk",
"TOOL_REPO": "best-tools",
"TOOL_REF": "tool-branch",
"TYPE": release.ReleaseTypeOfficial,
"TYPE_TAG": release.ReleaseTypeOfficial,
"FORCE_BUILD_KREL": "true",
"MAJOR_VERSION_TAG": "1",
"MINOR_VERSION_TAG": "16",
"PATCH_VERSION_TAG": "0",
Expand All @@ -315,17 +322,19 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
ReleaseType: release.ReleaseTypeBeta,
GcpUser: "test-user",
},
repoMock: mockRepo(),
versionMock: mockVersion("v1.19.0-alpha.2.763+2da917d3701904"),
releaseMock: mockRelease("1.19.0-beta.0"),
toolOrg: "honk",
toolRepo: "best-tools",
toolRef: "tool-branch",
repoMock: mockRepo(),
versionMock: mockVersion("v1.19.0-alpha.2.763+2da917d3701904"),
releaseMock: mockRelease("1.19.0-beta.0"),
toolOrg: "honk",
toolRepo: "best-tools",
toolRef: "tool-branch",
forceBuildKrel: "true",
expected: map[string]string{
"RELEASE_BRANCH": "release-1.19",
"TOOL_ORG": "honk",
"TOOL_REPO": "best-tools",
"TOOL_REF": "tool-branch",
"FORCE_BUILD_KREL": "true",
"TYPE": release.ReleaseTypeBeta,
"TYPE_TAG": release.ReleaseTypeBeta,
"MAJOR_VERSION_TAG": "1",
Expand All @@ -345,14 +354,16 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
ReleaseType: release.ReleaseTypeRC,
GcpUser: "test-user",
},
repoMock: mockRepo(),
versionMock: mockVersion("v1.18.6-rc.0.15+e38139724f8f00"),
releaseMock: mockRelease("1.18.6-rc.1"),
repoMock: mockRepo(),
versionMock: mockVersion("v1.18.6-rc.0.15+e38139724f8f00"),
releaseMock: mockRelease("1.18.6-rc.1"),
forceBuildKrel: "false",
expected: map[string]string{
"RELEASE_BRANCH": "release-1.18",
"TOOL_ORG": "",
"TOOL_REPO": "",
"TOOL_REF": "",
"FORCE_BUILD_KREL": "false",
"TYPE": release.ReleaseTypeRC,
"TYPE_TAG": release.ReleaseTypeRC,
"MAJOR_VERSION_TAG": "1",
Expand Down Expand Up @@ -380,6 +391,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
"TOOL_ORG": "",
"TOOL_REPO": "",
"TOOL_REF": "",
"FORCE_BUILD_KREL": "",
"TYPE": release.ReleaseTypeRC,
"TYPE_TAG": release.ReleaseTypeRC,
"MAJOR_VERSION_TAG": "1",
Expand All @@ -402,7 +414,7 @@ func TestSetGCBSubstitutionsSuccess(t *testing.T) {
sut.SetReleaseClient(tc.releaseMock)

subs, err := sut.SetGCBSubstitutions(
tc.toolOrg, tc.toolRepo, tc.toolRef, "gs://test-bucket",
tc.toolOrg, tc.toolRepo, tc.toolRef, "gs://test-bucket", tc.forceBuildKrel,
)
require.Nil(t, err)

Expand Down Expand Up @@ -449,7 +461,7 @@ func TestSetGCBSubstitutionsFailure(t *testing.T) {
sut := gcb.New(tc.gcbOpts)
sut.SetRepoClient(tc.repoMock)
sut.SetVersionClient(tc.versionMock)
_, err := sut.SetGCBSubstitutions("", "", "", "")
_, err := sut.SetGCBSubstitutions("", "", "", "", "")
require.Error(t, err)
}
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ func GetToolRef() string {
return env.Default("TOOL_REF", DefaultToolRef)
}

// GetForceBuildKrel checks if the 'FORCE_BUILD_KREL' environment variable is
// set. If 'FORCE_BUILD_KREL' is non-empty, it returns the value. Otherwise,
// it returns "false".
func GetForceBuildKrel() string {
return env.Default("FORCE_BUILD_KREL", "false")
}

// GetK8sOrg checks if the 'K8S_ORG' environment variable is set.
// If 'K8S_ORG' is non-empty, it returns the value. Otherwise, it returns DefaultK8sOrg.
func GetK8sOrg() string {
Expand Down
Loading