From 4544fc4ec0f1afa0dbae7d76c4d9de553ffa01f5 Mon Sep 17 00:00:00 2001 From: KMAnju-2021 Date: Fri, 21 Jul 2023 10:16:05 +0530 Subject: [PATCH] Automated upgrade support for Jenkins kind clusters Signed-off-by: KMAnju-2021 --- .github/workflows/conformance.yml | 3 +- .github/workflows/kind.yml | 14 +++++- .github/workflows/netpol_cyclonus.yml | 3 +- ci/jenkins/jobs/macros.yaml | 1 + ci/kind/kind-install.sh | 63 +++++++++++++++++++++++++++ ci/kind/version | 1 + 6 files changed, 79 insertions(+), 6 deletions(-) create mode 100755 ci/kind/kind-install.sh create mode 100755 ci/kind/version diff --git a/.github/workflows/conformance.yml b/.github/workflows/conformance.yml index 42b43aa5838..df6eadbdcd3 100644 --- a/.github/workflows/conformance.yml +++ b/.github/workflows/conformance.yml @@ -29,8 +29,6 @@ on: type: boolean default: false -env: - KIND_VERSION: v0.18.0 jobs: test: @@ -61,6 +59,7 @@ jobs: ./hack/build-antrea-linux-all.sh --pull - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin diff --git a/.github/workflows/kind.yml b/.github/workflows/kind.yml index 709c1eaa828..a4290ce09ea 100644 --- a/.github/workflows/kind.yml +++ b/.github/workflows/kind.yml @@ -11,8 +11,6 @@ on: - release-* - feature/* -env: - KIND_VERSION: v0.20.0 jobs: check-changes: @@ -95,6 +93,7 @@ jobs: docker load -i antrea-ubuntu.tar - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -156,6 +155,7 @@ jobs: docker load -i antrea-ubuntu.tar - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -223,6 +223,7 @@ jobs: docker load -i antrea-ubuntu.tar - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -290,6 +291,7 @@ jobs: docker load -i antrea-ubuntu.tar - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -351,6 +353,7 @@ jobs: docker load -i antrea-ubuntu.tar - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -424,6 +427,7 @@ jobs: docker load -i flow-aggregator.tar - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -486,6 +490,7 @@ jobs: docker tag antrea/antrea-ubuntu-coverage:latest antrea/antrea-ubuntu:latest - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -530,6 +535,7 @@ jobs: docker tag antrea/antrea-ubuntu-coverage:latest antrea/antrea-ubuntu:latest - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -574,6 +580,7 @@ jobs: docker tag antrea/antrea-ubuntu-coverage:latest antrea/antrea-ubuntu:latest - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -618,6 +625,7 @@ jobs: docker tag antrea/antrea-ubuntu-coverage:latest antrea/antrea-ubuntu:latest - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -662,6 +670,7 @@ jobs: docker tag antrea/antrea-ubuntu-coverage:latest antrea/antrea-ubuntu:latest - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin @@ -703,6 +712,7 @@ jobs: docker tag antrea/antrea-ubuntu-coverage:latest antrea/antrea-ubuntu:latest - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin diff --git a/.github/workflows/netpol_cyclonus.yml b/.github/workflows/netpol_cyclonus.yml index edf91f7e545..824fed5eb85 100644 --- a/.github/workflows/netpol_cyclonus.yml +++ b/.github/workflows/netpol_cyclonus.yml @@ -4,8 +4,6 @@ on: # run once a day at midnight - cron: '0 0 * * *' -env: - KIND_VERSION: v0.20.0 jobs: test-netpol-cyclonus: @@ -22,6 +20,7 @@ jobs: - run: make - name: Install Kind run: | + KIND_VERSION=$(head -n1 ./ci/kind/version) curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-$(uname)-amd64 chmod +x ./kind sudo mv kind /usr/local/bin diff --git a/ci/jenkins/jobs/macros.yaml b/ci/jenkins/jobs/macros.yaml index b15ecf1f26c..4fa4fc13753 100644 --- a/ci/jenkins/jobs/macros.yaml +++ b/ci/jenkins/jobs/macros.yaml @@ -239,6 +239,7 @@ # we have configured for running conformance and NetworkPolicy tests on Kind, # so clusters older than that can de deleted safely. ./ci/kind/kind-setup.sh destroy --all --until 135 + ./ci/kind/kind-install.sh ./ci/kind/kind-setup.sh --antrea-cni create "${{JOB_NAME}}-${{BUILD_NUMBER}}" kind export kubeconfig -n "${{JOB_NAME}}-${{BUILD_NUMBER}}" --kubeconfig ${{PWD}}/.kube/config set +ex diff --git a/ci/kind/kind-install.sh b/ci/kind/kind-install.sh new file mode 100755 index 00000000000..75f9eef361a --- /dev/null +++ b/ci/kind/kind-install.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# Copyright 2023 Antrea Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eo pipefail +LATEST_KIND_VERSION=$(head -n1 ./ci/kind/version) + +# on linux +function upgrade_kind { + arch_name="$(uname -m)" + binary_name="" + case "$arch_name" in + "x86_64") + binary_name="kind-linux-amd64" + ;; + "aarch64") + binary_name="kind-linux-arm64" + ;; + *) + echoerr "Unsupported platform $arch_name" + exit 1 + ;; + esac + + set +e + curl -Lo ./kind https://kind.sigs.k8s.io/dl/$LATEST_KIND_VERSION/$binary_name + chmod +x ./kind + sudo mv kind /usr/local/bin + if [[ $? -ne 0 ]]; then + echoerr "Failed to upgrade Kind version $LATEST_KIND_VERSION" + exit 1 + else + echo "Kind version $LATEST_KIND_VERSION upgraded successfully" + fi + set -e +} + +CMD_RETURN_CODE=0 +kind_version=$(kind version | awk '{print substr($2, 1)}') || CMD_RETURN_CODE=$? || true +if [[ ${CMD_RETURN_CODE} -ne 0 ]]; then + echo "=== Installing Kind ===" + upgrade_kind + exit 0 +elif [[ "$kind_version" != "$LATEST_KIND_VERSION" ]]; then + echo "=== Upgrading Kind to the latest version $LATEST_KIND_VERSION ===" + upgrade_kind +else + echo "=== Existing Kind version $kind_version is up to date ===" + exit 0 +fi + diff --git a/ci/kind/version b/ci/kind/version new file mode 100755 index 00000000000..1847373e96d --- /dev/null +++ b/ci/kind/version @@ -0,0 +1 @@ +v0.20.0