From 4211c15ecaa007a00edc0babff26bc32ad3b5c64 Mon Sep 17 00:00:00 2001 From: Loic Devulder Date: Wed, 11 Dec 2024 11:42:24 +0100 Subject: [PATCH] ci/airgap: allow to use specific version of Rancher Signed-off-by: Loic Devulder --- tests/e2e/airgap_test.go | 10 ++++-- tests/scripts/build-airgap | 70 ++++++++++++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/tests/e2e/airgap_test.go b/tests/e2e/airgap_test.go index 65fb6d8fc..90b761754 100644 --- a/tests/e2e/airgap_test.go +++ b/tests/e2e/airgap_test.go @@ -18,6 +18,7 @@ import ( "os" "os/exec" "regexp" + "strings" "time" . "github.com/onsi/ginkgo/v2" @@ -33,10 +34,13 @@ var _ = Describe("E2E - Build the airgap archive", Label("prepare-archive"), fun if certManagerVersion == "" { certManagerVersion = "latest" } + if rancherVersion == "" { + rancherVersion = "latest" + } // Could be useful for manual debugging! - GinkgoWriter.Printf("Executed command: %s %s %s %s %s %s\n", airgapBuildScript, k8sUpstreamVersion, certManagerVersion, rancherChannel, k8sDownstreamVersion, operatorRepo) - out, err := exec.Command(airgapBuildScript, k8sUpstreamVersion, certManagerVersion, rancherChannel, k8sDownstreamVersion, operatorRepo).CombinedOutput() + GinkgoWriter.Printf("Executed command: %s %s %s %s %s %s %s\n", airgapBuildScript, k8sUpstreamVersion, certManagerVersion, rancherChannel, rancherVersion, k8sDownstreamVersion, operatorRepo) + out, err := exec.Command(airgapBuildScript, k8sUpstreamVersion, certManagerVersion, rancherChannel, rancherVersion, k8sDownstreamVersion, operatorRepo).CombinedOutput() Expect(err).To(Not(HaveOccurred()), string(out)) }) }) @@ -194,7 +198,7 @@ var _ = Describe("E2E - Deploy K3S/Rancher in airgap environment", Label("airgap // Set flags for Rancher Manager installation flags := []string{ - "upgrade", "--install", "rancher", string(rancherManagerChart), + "upgrade", "--install", "rancher", strings.TrimSpace(string(rancherManagerChart)), "--namespace", "cattle-system", "--create-namespace", "--set", "hostname=" + rancherManager, diff --git a/tests/scripts/build-airgap b/tests/scripts/build-airgap index af017f860..b827960a9 100755 --- a/tests/scripts/build-airgap +++ b/tests/scripts/build-airgap @@ -56,8 +56,9 @@ function RunSkopeoCmdWithRetry() { K3S_UPSTREAM_VERSION=$1 CERT_MANAGER_VERSION=$2 RANCHER_CHANNEL=$3 -K3S_DOWNSTREAM_VERSION=$4 -ELEMENTAL_REPO=$5 +RANCHER_VERSION=$4 +K3S_DOWNSTREAM_VERSION=$5 +ELEMENTAL_REPO=$6 DEPLOY_AIRGAP_SCRIPT=$(realpath ../scripts/deploy-airgap) OPT_RANCHER="${HOME}/airgap_rancher" REPO_SERVER="rancher-manager.test:5000" @@ -107,14 +108,37 @@ done # Get Helm Charts cd ${OPT_RANCHER}/helm/ +# Define Rancher Manager repos depending of the needed version +case ${RANCHER_CHANNEL} in + prime) + RANCHER_CHART_REPO="https://charts.rancher.com/server-charts/prime" + ;; + prime-optimus) + RANCHER_CHART_REPO="https://charts.optimus.rancher.io/server-charts/latest" + ;; + prime-optimus-alpha) + RANCHER_CHART_REPO="https://charts.optimus.rancher.io/server-charts/alpha" + RANCHER_IMAGES_REPO="stgregistry.suse.com" + ;; + alpha|latest|stable) + RANCHER_CHART_REPO="https://releases.rancher.com/server-charts/${RANCHER_CHANNEL}" + RANCHER_IMAGES_REPO="stgregistry.suse.com" + ;; + *) + error "Rancher channel '${RANCHER_CHANNEL}' unknown!" + ;; +esac + # Add repos RunHelmCmdWithRetry repo add jetstack https://charts.jetstack.io > /dev/null 2>&1 -RunHelmCmdWithRetry repo add rancher-${RANCHER_CHANNEL} https://releases.rancher.com/server-charts/${RANCHER_CHANNEL} > /dev/null 2>&1 +RunHelmCmdWithRetry repo add rancher-${RANCHER_CHANNEL} ${RANCHER_CHART_REPO} > /dev/null 2>&1 RunHelmCmdWithRetry repo update > /dev/null 2>&1 # Get CertManager charts -[[ "${CERT_MANAGER_VERSION}" != "latest" ]] && VER_OPT="--version ${CERT_MANAGER_VERSION}" -RunHelmCmdWithRetry pull jetstack/cert-manager ${VER_OPT} > /dev/null 2>&1 +[[ "${CERT_MANAGER_VERSION}" == "latest" ]] \ + && unset VER_OPT \ + || VER_OPT="--version ${CERT_MANAGER_VERSION}" +RunHelmCmdWithRetry pull ${VER_OPT} jetstack/cert-manager > /dev/null 2>&1 # Get CertManager version CERT_MANAGER_VERSION=$(ls cert-manager-*.tgz 2>/dev/null) @@ -122,19 +146,28 @@ CERT_MANAGER_VERSION=${CERT_MANAGER_VERSION#cert-manager-*} CERT_MANAGER_VERSION=${CERT_MANAGER_VERSION%.*} # Get Rancher charts -[[ "${RANCHER_CHANNEL}" =~ (latest|alpha) ]] && DEVEL="--devel" || unset DEVEL -RunHelmCmdWithRetry pull ${DEVEL} rancher-${RANCHER_CHANNEL}/rancher > /dev/null 2>&1 +[[ "${RANCHER_CHANNEL}" =~ (alpha|latest|optimus) ]] \ + && DEVEL="--devel" \ + || unset DEVEL +[[ "${RANCHER_VERSION}" == "latest" ]] \ + && unset VER_OPT \ + || VER_OPT="--version ${RANCHER_VERSION}" +RunHelmCmdWithRetry pull ${DEVEL} ${VER_OPT} rancher-${RANCHER_CHANNEL}/rancher > /dev/null 2>&1 # Get Elemental charts -[[ "${ELEMENTAL_REPO}" =~ (/dev/|/staging/) ]] && DEVEL="--devel" || unset DEVEL +[[ "${ELEMENTAL_REPO}" =~ (/dev/|/staging/) ]] \ + && DEVEL="--devel" \ + || unset DEVEL for i in elemental-operator-chart elemental-operator-crds-chart ; do RunHelmCmdWithRetry pull ${DEVEL} ${ELEMENTAL_REPO}/${i} > /dev/null 2>&1 done -# Get Rancher Manager version -RANCHER_MANAGER_VERSION=$(ls rancher-*.tgz 2>/dev/null) -RANCHER_MANAGER_VERSION=${RANCHER_MANAGER_VERSION#rancher-*} -RANCHER_MANAGER_VERSION=${RANCHER_MANAGER_VERSION%.*} +# Get Rancher Manager version if not already set +if [[ -z "${RANCHER_VERSION}" || "${RANCHER_VERSION}" == "latest" ]]; then + RANCHER_VERSION=$(ls rancher-*.tgz 2>/dev/null) + RANCHER_VERSION=${RANCHER_VERSION#rancher-*} + RANCHER_VERSION=${RANCHER_VERSION%.*} +fi # Get the Elemental repositories ELEMENTAL_AIRGAP_REPO=https://raw.githubusercontent.com/rancher/elemental-operator/main/scripts @@ -147,7 +180,9 @@ rm -f ${ELEMENTAL_AIRGAP_SCRIPT} cd ${OPT_RANCHER}/images/ # Rancher image list -RANCHER_REPO=https://github.com/rancher/rancher/releases/download/v${RANCHER_MANAGER_VERSION} +[[ "${RANCHER_CHANNEL}" =~ prime ]] \ + && RANCHER_REPO=https://prime.ribs.rancher.io/rancher/v${RANCHER_VERSION} \ + || RANCHER_REPO=https://github.com/rancher/rancher/releases/download/v${RANCHER_VERSION} RANCHER_IMAGES_FILE=rancher-images.txt curl -sOL ${RANCHER_REPO}/${RANCHER_IMAGES_FILE} @@ -175,7 +210,14 @@ mv -f ${OPT_RANCHER}/helm/${ELEMENTAL_IMAGES_FILE} . loop=0 for i in $(< ${CERT_IMAGES_FILE}) $(< ${ELEMENTAL_IMAGES_FILE}) $(< ${RANCHER_IMAGES_FILE}); do mkdir -p ${i%/*} - RunSkopeoCmdWithRetry copy docker://${i} docker-archive:${i/:/_}.tar:${i} & + + # Devel/Staging versions of Rancher are hosted in a specific registry + [[ "${i}" =~ (rancher/rancher-agent:|rancher/rancher:) && -n "${RANCHER_IMAGES_REPO}" ]] \ + && j="${RANCHER_IMAGES_REPO}/${i}" \ + || j="${i}" + + # Copy images + RunSkopeoCmdWithRetry copy docker://${j} docker-archive:${i/:/_}.tar:${i} & # Wait for skopeo jobs to finish if we already have too much jobs in parallel # This is to avoid the "too many requests to registry" error!