Skip to content

Commit

Permalink
Use latest krel binary release instead of compilation in cloudbuild
Browse files Browse the repository at this point in the history
This pins `krel` to the latest available release for all cloudbuild
jobs, which usually run in production. It should also speedup the whole
process because we do not have to download and compile all those golang
dependencies.

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Nov 14, 2023
1 parent 9e6769c commit 15bc44d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 48 deletions.
13 changes: 9 additions & 4 deletions docs/krel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ Kubernetes Releases. This includes manually executed tasks like generating the R

## Installation

Either Compile krel by running the `compile-release-tools` script from the root of this repo:
Either download the latest version of `krel` by using the `hack/get-krel` script:

```shell
./compile-release-tools krel
./hack/get-krel
```
Or

Run the following command in the terminal:
Or compile `krel` by running the `compile-release-tools` script from the root of this repo:

```shell
./compile-release-tools krel
```

Or run the following command in the terminal:

```shell
go install k8s.io/release/cmd/krel@latest
```

Expand Down
10 changes: 4 additions & 6 deletions gcb/fast-forward/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ steps:
echo "Checking out ${_TOOL_REF}"
git checkout ${_TOOL_REF}
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION_LATEST}
dir: "go/src/k8s.io/release"
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: go/src/k8s.io/release
env:
- "GOPATH=/workspace/go"
- "GOBIN=/workspace/bin"
- KREL_OUTPUT_PATH=/workspace/bin/krel
args:
- "./compile-release-tools"
- "krel"
- ./hack/get-krel

- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: "/workspace"
Expand Down
10 changes: 4 additions & 6 deletions gcb/obs-release/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ steps:
echo "Checking out ${_TOOL_REF}"
git checkout ${_TOOL_REF}
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION_LATEST}
dir: "go/src/k8s.io/release"
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: go/src/k8s.io/release
env:
- "GOPATH=/workspace/go"
- "GOBIN=/workspace/bin"
- KREL_OUTPUT_PATH=/workspace/bin/krel
args:
- "./compile-release-tools"
- "krel"
- ./hack/get-krel

- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: "/workspace"
Expand Down
10 changes: 4 additions & 6 deletions gcb/obs-stage/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@ steps:
echo "Checking out ${_TOOL_REF}"
git checkout ${_TOOL_REF}
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION_LATEST}
dir: "go/src/k8s.io/release"
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: go/src/k8s.io/release
env:
- "GOPATH=/workspace/go"
- "GOBIN=/workspace/bin"
- KREL_OUTPUT_PATH=/workspace/bin/krel
args:
- "./compile-release-tools"
- "krel"
- ./hack/get-krel

- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: "/workspace"
Expand Down
10 changes: 4 additions & 6 deletions gcb/release/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@ steps:
echo "Checking out ${_TOOL_REF}"
git checkout ${_TOOL_REF}
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION_LATEST}
dir: "go/src/k8s.io/release"
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: go/src/k8s.io/release
env:
- "GOPATH=/workspace/go"
- "GOBIN=/workspace/bin"
- KREL_OUTPUT_PATH=/workspace/bin/krel
args:
- "./compile-release-tools"
- "krel"
- ./hack/get-krel

- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: "/workspace"
Expand Down
10 changes: 4 additions & 6 deletions gcb/stage/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,12 @@ steps:
echo "Checking out ${_TOOL_REF}"
git checkout ${_TOOL_REF}
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION_LATEST}
dir: "go/src/k8s.io/release"
- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: go/src/k8s.io/release
env:
- "GOPATH=/workspace/go"
- "GOBIN=/workspace/bin"
- KREL_OUTPUT_PATH=/workspace/bin/krel
args:
- "./compile-release-tools"
- "krel"
- ./hack/get-krel

- name: gcr.io/k8s-staging-releng/k8s-cloud-builder:${_KUBE_CROSS_VERSION}
dir: "/workspace"
Expand Down
21 changes: 21 additions & 0 deletions hack/get-krel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail

curl_retry() {
curl -sSfL --retry 5 --retry-delay 3 "$@"
}

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

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

echo "Downloading krel from GCB bucket…"
GCB_URL="https://storage.googleapis.com/k8s-artifacts-sig-release/kubernetes/release/$LATEST_RELEASE/krel-amd64-linux"
curl_retry "$GCB_URL" -o "$KREL_OUTPUT_PATH"
chmod +x "$KREL_OUTPUT_PATH"

echo "Done, output of 'krel version':"
"$KREL_OUTPUT_PATH" version
14 changes: 0 additions & 14 deletions pkg/gcp/gcb/gcb.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,21 +377,7 @@ func (g *GCB) SetGCBSubstitutions(toolOrg, toolRepo, toolRef, gcsBucket string)
logrus.Infof("KubeCross version not set for %s, falling back to latest", g.options.Branch)
}

kcVersionLatest := kcVersionBranch
if g.options.Branch != git.DefaultBranch {
kcVersionLatest, err = kc.Latest()
if err != nil {
return gcbSubs, fmt.Errorf("retrieve latest kube-cross version: %w", err)
}

// if kcVersionBranch is empty, the branch does not exist yet, we use
// the latest kubecross version
if kcVersionBranch == "" {
kcVersionBranch = kcVersionLatest
}
}
gcbSubs["KUBE_CROSS_VERSION"] = kcVersionBranch
gcbSubs["KUBE_CROSS_VERSION_LATEST"] = kcVersionLatest

switch {
case g.options.OBSStage:
Expand Down

0 comments on commit 15bc44d

Please sign in to comment.