Skip to content

Commit

Permalink
Merge branch 'master' into haitao/newer_golang_patch_sep2024
Browse files Browse the repository at this point in the history
  • Loading branch information
haitch committed Sep 17, 2024
2 parents c5234f0 + 27310fb commit a8f7105
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 43 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6
uses: github/codeql-action/init@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6
uses: github/codeql-action/autobuild@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
Expand All @@ -83,4 +83,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6
uses: github/codeql-action/analyze@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
2 changes: 1 addition & 1 deletion .github/workflows/scorecards-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@4dd16135b69a43b6c8efb853346f8437d92d3c93 # v3.26.6
uses: github/codeql-action/upload-sarif@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
with:
sarif_file: results.sarif
2 changes: 1 addition & 1 deletion cmd/schedule-builder/cmd/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func updatePatchSchedule(refTime time.Time, schedule PatchSchedule, eolBranches
}

if refTime.After(upcomingTargetDate) {
logrus.Infof("Skipping outdated upcoming release for %s (%s)", upcomingRelease.Release, upcomingRelease.TargetDate)
logrus.Infof("Skipping outdated upcoming release for %s", upcomingRelease.TargetDate)
continue
}

Expand Down
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ require (
golang.org/x/text v0.18.0
google.golang.org/api v0.172.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.31.0
k8s.io/apimachinery v0.31.1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
sigs.k8s.io/bom v0.6.0
sigs.k8s.io/mdtoc v1.4.0
sigs.k8s.io/promo-tools/v3 v3.6.0
sigs.k8s.io/release-sdk v0.12.1
sigs.k8s.io/release-utils v0.8.4
sigs.k8s.io/release-utils v0.8.5
sigs.k8s.io/yaml v1.4.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1286,8 +1286,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.28.3 h1:Gj1HtbSdB4P08C8rs9AR94MfSGpRhJgsS+GF9V26xMM=
k8s.io/api v0.28.3/go.mod h1:MRCV/jr1dW87/qJnZ57U5Pak65LGmQVkKTzf3AtKFHc=
k8s.io/apimachinery v0.31.0 h1:m9jOiSr3FoSSL5WO9bjm1n6B9KROYYgNZOb4tyZ1lBc=
k8s.io/apimachinery v0.31.0/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/apimachinery v0.31.1 h1:mhcUBbj7KUjaVhyXILglcVjuS4nYXiwC+KKFBgIVy7U=
k8s.io/apimachinery v0.31.1/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
k8s.io/client-go v0.28.3 h1:2OqNb72ZuTZPKCl+4gTKvqao0AMOl9f3o2ijbAj3LI4=
k8s.io/client-go v0.28.3/go.mod h1:LTykbBp9gsA7SwqirlCXBWtK0guzfhpoW4qSm7i9dxo=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
Expand Down Expand Up @@ -1317,8 +1317,8 @@ sigs.k8s.io/promo-tools/v3 v3.6.0 h1:C2L08ezrWm1aZI8Emd3iZPZQserLPRgzuqQVxvI0PUI
sigs.k8s.io/promo-tools/v3 v3.6.0/go.mod h1:XJ3jy0hJYs+hWKt8XsLHFzGQV8PUtvllvbxjN/E5RXI=
sigs.k8s.io/release-sdk v0.12.1 h1:/Q+yWpl33EnFx1b7xh6FnbioWSRUTrVkigL4KZVTrkU=
sigs.k8s.io/release-sdk v0.12.1/go.mod h1:nnB4tt1g0VXMUCIYzDzPVqNI896OQrWipE6WbyZ6FSk=
sigs.k8s.io/release-utils v0.8.4 h1:4QVr3UgbyY/d9p74LBhg0njSVQofUsAZqYOzVZBhdBw=
sigs.k8s.io/release-utils v0.8.4/go.mod h1:m1bHfscTemQp+z+pLCZnkXih9n0+WukIUU70n6nFnU0=
sigs.k8s.io/release-utils v0.8.5 h1:FUtFqEAN621gSXv0L7kHyWruBeS7TUU9aWf76olX7uQ=
sigs.k8s.io/release-utils v0.8.5/go.mod h1:qsm5bdxdgoHkD8HsXpgme2/c3mdsNaiV53Sz2HmKeJA=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
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
9 changes: 6 additions & 3 deletions pkg/release/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func (p *Publisher) PublishToGcs(
return fmt.Errorf("write latest version file: %w", err)
}

logrus.Infof("Running `gsutil cp` from %s to: %s", latestFile, publishFileDst)
if err := p.client.GSUtil(
"-m",
"-h", "Content-Type:text/plain",
Expand All @@ -374,20 +375,22 @@ func (p *Publisher) PublishToGcs(
var content string
if !privateBucket {
// If public, validate public link
logrus.Infof("Validating uploaded version file using HTTP at %s", publicLink)
response, err := p.client.GetURLResponse(publicLink)
if err != nil {
return fmt.Errorf("get content of %s: %w", publicLink, err)
}
content = response
} else {
response, err := p.client.GSUtilOutput("cat", publicLink)
// Use the private location
logrus.Infof("Validating uploaded version file using `gsutil cat` at %s", publishFileDst)
response, err := p.client.GSUtilOutput("cat", publishFileDst)
if err != nil {
return fmt.Errorf("get content of %s: %w", publicLink, err)
return fmt.Errorf("get content of %s: %w", publishFileDst, err)
}
content = response
}

logrus.Infof("Validating uploaded version file at %s", publicLink)
if version != content {
return fmt.Errorf(
"version %s it not equal response %s",
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

0 comments on commit a8f7105

Please sign in to comment.