From 1de3359a33606f297b084495dff6e2efcd76fcfc Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Wed, 21 Aug 2024 11:59:31 +0200 Subject: [PATCH] Build krel from sources when not using default `TOOL_*` values This allos testing GCB by setting one of `TOOL_ORG`, `TOOL_REPO` or `TOOL_REF`. Signed-off-by: Sascha Grunert --- gcb/fast-forward/cloudbuild.yaml | 3 +++ gcb/obs-release/cloudbuild.yaml | 3 +++ gcb/obs-stage/cloudbuild.yaml | 3 +++ gcb/release/cloudbuild.yaml | 3 +++ gcb/stage/cloudbuild.yaml | 3 +++ hack/get-krel | 24 ++++++++++++++++++------ 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/gcb/fast-forward/cloudbuild.yaml b/gcb/fast-forward/cloudbuild.yaml index 498830cc414..6cedd847b40 100644 --- a/gcb/fast-forward/cloudbuild.yaml +++ b/gcb/fast-forward/cloudbuild.yaml @@ -56,6 +56,9 @@ steps: dir: go/src/k8s.io/release env: - KREL_OUTPUT_PATH=/workspace/bin/krel + - "TOOL_ORG=${_TOOL_ORG}" + - "TOOL_REPO=${_TOOL_REPO}" + - "TOOL_REF=${_TOOL_REF}" args: - ./hack/get-krel diff --git a/gcb/obs-release/cloudbuild.yaml b/gcb/obs-release/cloudbuild.yaml index 42f38d47625..465437b558b 100644 --- a/gcb/obs-release/cloudbuild.yaml +++ b/gcb/obs-release/cloudbuild.yaml @@ -56,6 +56,9 @@ steps: dir: go/src/k8s.io/release env: - KREL_OUTPUT_PATH=/workspace/bin/krel + - "TOOL_ORG=${_TOOL_ORG}" + - "TOOL_REPO=${_TOOL_REPO}" + - "TOOL_REF=${_TOOL_REF}" args: - ./hack/get-krel diff --git a/gcb/obs-stage/cloudbuild.yaml b/gcb/obs-stage/cloudbuild.yaml index 235bd674fac..cfacd5c8b31 100644 --- a/gcb/obs-stage/cloudbuild.yaml +++ b/gcb/obs-stage/cloudbuild.yaml @@ -56,6 +56,9 @@ steps: dir: go/src/k8s.io/release env: - KREL_OUTPUT_PATH=/workspace/bin/krel + - "TOOL_ORG=${_TOOL_ORG}" + - "TOOL_REPO=${_TOOL_REPO}" + - "TOOL_REF=${_TOOL_REF}" args: - ./hack/get-krel diff --git a/gcb/release/cloudbuild.yaml b/gcb/release/cloudbuild.yaml index 869deaa4785..478e7728f06 100644 --- a/gcb/release/cloudbuild.yaml +++ b/gcb/release/cloudbuild.yaml @@ -59,6 +59,9 @@ steps: dir: go/src/k8s.io/release env: - KREL_OUTPUT_PATH=/workspace/bin/krel + - "TOOL_ORG=${_TOOL_ORG}" + - "TOOL_REPO=${_TOOL_REPO}" + - "TOOL_REF=${_TOOL_REF}" args: - ./hack/get-krel diff --git a/gcb/stage/cloudbuild.yaml b/gcb/stage/cloudbuild.yaml index 90127a06db7..3e0ae7427b2 100644 --- a/gcb/stage/cloudbuild.yaml +++ b/gcb/stage/cloudbuild.yaml @@ -60,6 +60,9 @@ steps: dir: go/src/k8s.io/release env: - KREL_OUTPUT_PATH=/workspace/bin/krel + - "TOOL_ORG=${_TOOL_ORG}" + - "TOOL_REPO=${_TOOL_REPO}" + - "TOOL_REF=${_TOOL_REF}" args: - ./hack/get-krel diff --git a/hack/get-krel b/hack/get-krel index c2abecafc58..5a53081a239 100755 --- a/hack/get-krel +++ b/hack/get-krel @@ -22,17 +22,29 @@ curl_retry() { curl -sSfL --retry 5 --retry-delay 3 "$@" } +DEFAULT_TOOL_ORG=kubernetes +DEFAULT_TOOL_REPO=release +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}} 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" +if [[ "$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" -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 "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" +else + echo "Building krel from sources" + go build -o "$KREL_OUTPUT_PATH" ./cmd/krel +fi echo "Done, output of 'krel version':" "$KREL_OUTPUT_PATH" version