diff --git a/manager/integration/Dockerfile b/manager/integration/Dockerfile index 4bf52c20ed..7e5db78bc8 100644 --- a/manager/integration/Dockerfile +++ b/manager/integration/Dockerfile @@ -21,7 +21,10 @@ RUN curl -sO https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_ wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_${ARCH}.zip && \ unzip terraform_${TERRAFORM_VERSION}_linux_${ARCH}.zip && rm terraform_${TERRAFORM_VERSION}_linux_${ARCH}.zip && \ mv terraform /usr/bin/terraform && \ - chmod +x /usr/bin/terraform + chmod +x /usr/bin/terraform && \ + curl -s -o flux_install.sh https://fluxcd.io/install.sh && \ + chmod 700 flux_install.sh && \ + ./flux_install.sh RUN curl -L https://github.com/jonelo/jacksum/releases/download/v3.4.0/jacksum-3.4.0.jar --output /jacksum.jar @@ -34,5 +37,6 @@ WORKDIR /integration/tests ADD pipelines/utilities ./pipelines/utilities ADD pipelines/helm/scripts/upgrade-longhorn.sh ./pipelines/helm/scripts/upgrade-longhorn.sh ADD pipelines/rancher/scripts/upgrade-longhorn.sh ./pipelines/rancher/scripts/upgrade-longhorn.sh +ADD pipelines/flux/scripts/upgrade-longhorn.sh ./pipelines/flux/scripts/upgrade-longhorn.sh ENTRYPOINT ["./run.sh"] diff --git a/manager/integration/deploy/test.yaml b/manager/integration/deploy/test.yaml index 28ef1d57f0..7ab9b22f73 100644 --- a/manager/integration/deploy/test.yaml +++ b/manager/integration/deploy/test.yaml @@ -5,50 +5,13 @@ metadata: namespace: default --- apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: longhorn-test-role -rules: -- apiGroups: [""] - resources: ["nodes", "nodes/status", "pods", "pods/exec", "persistentvolumes", "persistentvolumeclaims", - "persistentvolumeclaims/status", "secrets", "services", "serviceaccounts", "namespaces", "configmaps"] - verbs: ["*"] -- apiGroups: ["scheduling.k8s.io"] - resources: ["priorityclasses"] - verbs: ["*"] -- apiGroups: ["storage.k8s.io"] - resources: ["storageclasses"] - verbs: ["*"] -- apiGroups: ["apps"] - resources: ["statefulsets", "deployments", "daemonsets"] - verbs: ["*"] -- apiGroups: ["rbac.authorization.k8s.io"] - resources: ["clusterroles", "clusterrolebindings", "rolebindings", "roles"] - verbs: ["*"] -- apiGroups: ["apiextensions.k8s.io"] - resources: ["customresourcedefinitions"] - verbs: ["*"] -- apiGroups: ["policy"] - resources: ["podsecuritypolicies", "poddisruptionbudgets"] - verbs: ["*"] -- apiGroups: ["snapshot.storage.k8s.io"] - resources: ["*"] - verbs: ["*"] -- apiGroups: ["batch"] - resources: ["cronjobs", "jobs"] - verbs: ["*"] -- apiGroups: ["longhorn.io"] - resources: ["supportbundles", "supportbundles/status"] - verbs: ["*"] ---- -apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: longhorn-test-bind roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: longhorn-test-role + name: cluster-admin subjects: - kind: ServiceAccount name: longhorn-test-service-account diff --git a/manager/integration/tests/common.py b/manager/integration/tests/common.py index 868f05befe..564c2b729d 100644 --- a/manager/integration/tests/common.py +++ b/manager/integration/tests/common.py @@ -4444,7 +4444,6 @@ def wait_for_backup_restore_completed(client, name, backup_name): complete = False for i in range(RETRY_COUNTS): v = client.by_id_volume(name) - print(f"volume = {v}") if v.controllers and len(v.controllers) != 0 and \ v.controllers[0].lastRestoredBackup == backup_name: complete = True diff --git a/manager/integration/tests/conftest.py b/manager/integration/tests/conftest.py index 033e4d896d..052f703bbd 100644 --- a/manager/integration/tests/conftest.py +++ b/manager/integration/tests/conftest.py @@ -22,6 +22,8 @@ RANCHER_SECRET_KEY = "--rancher-secret-key" RANCHER_CHART_INSTALL_VERSION = "--rancher-chart-install-version" LONGHORN_REPO = "--longhorn-repo" +FLUX_HELM_CHART_URL = "--flux-helm-chart-url" +FLUX_HELM_CHART_VERSION = "--flux-helm-chart-version" UPGRADE_LH_REPO_URL = "--upgrade-lh-repo-url" UPGRADE_LH_REPO_BRANCH = "--upgrade-lh-repo-branch" UPGRADE_LH_MANAGER_IMAGE = "--upgrade-lh-manager-image" @@ -91,6 +93,16 @@ def pytest_addoption(parser): the longhorn dockerhub repo of longhorn components like longhornio or rancher''') + parser.addoption(FLUX_HELM_CHART_URL, action="store", + default="https://charts.longhorn.io", + help='''if longhorn install method is flux, specify the + url of flux helm repository resource''') + + parser.addoption(FLUX_HELM_CHART_VERSION, action="store", + default="", + help='''if longhorn install method is flux, specify the + chart version when create flux helm release resource''') + longhorn_repo_url =\ "https://github.com/longhorn/longhorn.git" parser.addoption(UPGRADE_LH_REPO_URL, action="store", diff --git a/manager/integration/tests/test_upgrade.py b/manager/integration/tests/test_upgrade.py index dbc2762ec7..09124d093c 100644 --- a/manager/integration/tests/test_upgrade.py +++ b/manager/integration/tests/test_upgrade.py @@ -90,6 +90,16 @@ def longhorn_repo(request): return request.config.getoption("--longhorn-repo") +@pytest.fixture +def flux_helm_chart_url(request): + return request.config.getoption("--flux-helm-chart-url") + + +@pytest.fixture +def flux_helm_chart_version(request): + return request.config.getoption("--flux-helm-chart-version") + + @pytest.fixture def upgrade_longhorn_repo_url(request): return request.config.getoption("--upgrade-lh-repo-url") @@ -142,6 +152,8 @@ def longhorn_upgrade(longhorn_install_method, rancher_secret_key, rancher_chart_install_version, longhorn_repo, + flux_helm_chart_url, + flux_helm_chart_version, longhorn_repo_url, longhorn_repo_branch, longhorn_manager_image, @@ -152,12 +164,17 @@ def longhorn_upgrade(longhorn_install_method, if longhorn_install_method == "manifest": command = "../scripts/upgrade-longhorn.sh" + process = subprocess.Popen([command, + longhorn_repo_url, + longhorn_repo_branch, + longhorn_manager_image, + longhorn_engine_image, + longhorn_instance_manager_image, + longhorn_share_manager_image, + longhorn_backing_image_manager_image], + shell=False) elif longhorn_install_method == "helm": command = "./pipelines/helm/scripts/upgrade-longhorn.sh" - elif longhorn_install_method == "rancher": - command = "./pipelines/rancher/scripts/upgrade-longhorn.sh" - - if longhorn_install_method != "rancher": process = subprocess.Popen([command, longhorn_repo_url, longhorn_repo_branch, @@ -167,7 +184,8 @@ def longhorn_upgrade(longhorn_install_method, longhorn_share_manager_image, longhorn_backing_image_manager_image], shell=False) - else: + elif longhorn_install_method == "rancher": + command = "./pipelines/rancher/scripts/upgrade-longhorn.sh" process = subprocess.Popen([command, rancher_hostname, rancher_access_key, @@ -175,6 +193,13 @@ def longhorn_upgrade(longhorn_install_method, rancher_chart_install_version, longhorn_repo], shell=False) + elif longhorn_install_method == "flux": + command = "./pipelines/flux/scripts/upgrade-longhorn.sh" + process = subprocess.Popen([command, + flux_helm_chart_url, + flux_helm_chart_version], + shell=False) + process.wait() if process.returncode == 0: longhorn_upgraded = True @@ -193,6 +218,8 @@ def test_upgrade(longhorn_upgrade_type, rancher_secret_key, rancher_chart_install_version, longhorn_repo, + flux_helm_chart_url, + flux_helm_chart_version, upgrade_longhorn_repo_url, upgrade_longhorn_repo_branch, upgrade_longhorn_manager_image, @@ -377,6 +404,8 @@ def test_upgrade(longhorn_upgrade_type, rancher_secret_key, rancher_chart_install_version, longhorn_repo, + flux_helm_chart_url, + flux_helm_chart_version, longhorn_repo_url, longhorn_repo_branch, longhorn_manager_image, diff --git a/pipelines/flux/Dockerfile.setup b/pipelines/flux/Dockerfile.setup new file mode 100644 index 0000000000..1b5d03c5d7 --- /dev/null +++ b/pipelines/flux/Dockerfile.setup @@ -0,0 +1,37 @@ +From alpine:latest + +ARG KUBECTL_VERSION=v1.20.2 + +ARG RKE_VERSION=v1.3.4 + +ARG TERRAFORM_VERSION=1.3.5 + +ARG YQ_VERSION=v4.24.2 + +ENV WORKSPACE /src/longhorn-tests + +WORKDIR $WORKSPACE + +RUN wget -q https://storage.googleapis.com/kubernetes-release/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl && \ + mv kubectl /usr/local/bin/kubectl && \ + chmod +x /usr/local/bin/kubectl && \ + wget -q https://github.com/rancher/rke/releases/download/$RKE_VERSION/rke_linux-amd64 && \ + mv rke_linux-amd64 /usr/bin/rke && \ + chmod +x /usr/bin/rke && \ + wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \ + unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip && rm terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \ + mv terraform /usr/bin/terraform && \ + chmod +x /usr/bin/terraform && \ + wget -q "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" && \ + mv yq_linux_amd64 /usr/local/bin/yq && \ + chmod +x /usr/local/bin/yq && \ + apk add openssl openssh-client ca-certificates git rsync bash curl jq python3 py3-pip && \ + ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa && \ + curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && \ + chmod 700 get_helm.sh && \ + ./get_helm.sh && \ + curl -s -o flux_install.sh https://fluxcd.io/install.sh && \ + chmod 700 flux_install.sh && \ + ./flux_install.sh + +COPY [".", "$WORKSPACE"] diff --git a/pipelines/flux/Jenkinsfile b/pipelines/flux/Jenkinsfile new file mode 100644 index 0000000000..8aa97b2a4e --- /dev/null +++ b/pipelines/flux/Jenkinsfile @@ -0,0 +1,204 @@ +def imageName = "${JOB_BASE_NAME}-${env.BUILD_NUMBER}" +def summary +def WORKSPACE = "/src/longhorn-tests" +def BUILD_TRIGGER_BY = "\n${currentBuild.getBuildCauses()[0].shortDescription}" + +// define optional parameters +def SELINUX_MODE = params.SELINUX_MODE ? params.SELINUX_MODE : "" + +def CREDS_ID = JOB_BASE_NAME == "longhorn-tests-regression" ? "AWS_CREDS_RANCHER_QA" : "AWS_CREDS" +def REGISTRATION_CODE_ID = params.ARCH == "amd64" ? "REGISTRATION_CODE" : "REGISTRATION_CODE_ARM64" + +// parameters for air gap installation +def AIR_GAP_INSTALLATION = params.AIR_GAP_INSTALLATION ? params.AIR_GAP_INSTALLATION : false +def CIS_HARDENING = params.CIS_HARDENING ? params.CIS_HARDENING : false +def REGISTRY_URL +def REGISTRY_USERNAME +def REGISTRY_PASSWORD + +// parameter for hdd test +def USE_HDD = params.USE_HDD ? params.USE_HDD : false + +node { + + withCredentials([ + usernamePassword(credentialsId: CREDS_ID, passwordVariable: 'AWS_SECRET_KEY', usernameVariable: 'AWS_ACCESS_KEY'), + string(credentialsId: 'DO_CREDS', variable: 'DO_TOKEN'), + string(credentialsId: REGISTRATION_CODE_ID, variable: 'REGISTRATION_CODE'), + ]) { + + if (params.SEND_SLACK_NOTIFICATION) { + notifyBuild('STARTED', BUILD_TRIGGER_BY, params.NOTIFY_SLACK_CHANNEL) + } + + checkout scm + + try { + + if (params.AIR_GAP_INSTALLATION) { + + stage('airgap build') { + sh "airgap/scripts/build.sh" + sh """ docker run -itd --name airgap-${JOB_BASE_NAME}-${BUILD_NUMBER} \ + --env TF_VAR_longhorn_version=${LONGHORN_INSTALL_VERSION} \ + --env TF_VAR_do_token=${DO_TOKEN} \ + --env TF_VAR_aws_access_key=${AWS_ACCESS_KEY} \ + --env TF_VAR_aws_secret_key=${AWS_SECRET_KEY} \ + airgap-${JOB_BASE_NAME}-${BUILD_NUMBER} + """ + } + + stage ('airgap setup') { + sh "docker exec airgap-${JOB_BASE_NAME}-${BUILD_NUMBER} ./airgap/scripts/terraform-setup.sh" + REGISTRY_URL = sh ( + script: "docker exec airgap-${JOB_BASE_NAME}-${BUILD_NUMBER} terraform -chdir=./airgap/terraform output -raw registry_url", + returnStdout: true + ) + println REGISTRY_URL + REGISTRY_USERNAME = sh ( + script: "docker exec airgap-${JOB_BASE_NAME}-${BUILD_NUMBER} terraform -chdir=./airgap/terraform output -raw registry_username", + returnStdout: true + ) + REGISTRY_PASSWORD = sh ( + script: "docker exec airgap-${JOB_BASE_NAME}-${BUILD_NUMBER} terraform -chdir=./airgap/terraform output -raw registry_password", + returnStdout: true + ) + } + + } + + stage('build') { + + echo "Using credentials: $CREDS_ID" + echo "Using registration coce: $REGISTRATION_CODE_ID" + + sh "pipelines/flux/scripts/build.sh" + sh """ docker run -itd --name ${JOB_BASE_NAME}-${BUILD_NUMBER} \ + --env AIR_GAP_INSTALLATION=${AIR_GAP_INSTALLATION} \ + --env REGISTRY_URL=${REGISTRY_URL} \ + --env REGISTRY_USERNAME=${REGISTRY_USERNAME} \ + --env REGISTRY_PASSWORD=${REGISTRY_PASSWORD} \ + --env HELM_CHART_URL=${HELM_CHART_URL} \ + --env LONGHORN_TESTS_CUSTOM_IMAGE=${LONGHORN_TESTS_CUSTOM_IMAGE} \ + --env DISTRO=${DISTRO} \ + --env LONGHORN_INSTALL_VERSION=${LONGHORN_INSTALL_VERSION} \ + --env LONGHORN_STABLE_VERSION=${LONGHORN_STABLE_VERSION} \ + --env LONGHORN_TRANSIENT_VERSION=${LONGHORN_TRANSIENT_VERSION} \ + --env LONGHORN_TEST_CLOUDPROVIDER=${LONGHORN_TEST_CLOUDPROVIDER} \ + --env LONGHORN_UPGRADE_TEST=${LONGHORN_UPGRADE_TEST} \ + --env PYTEST_CUSTOM_OPTIONS="${PYTEST_CUSTOM_OPTIONS}" \ + --env BACKUP_STORE_TYPE="${BACKUP_STORE_TYPE}" \ + --env TF_VAR_use_hdd=${USE_HDD} \ + --env TF_VAR_arch=${ARCH} \ + --env TF_VAR_k8s_distro_name=${K8S_DISTRO_NAME} \ + --env TF_VAR_k8s_distro_version=${K8S_DISTRO_VERSION} \ + --env TF_VAR_aws_availability_zone=${AWS_AVAILABILITY_ZONE} \ + --env TF_VAR_aws_region=${AWS_REGION} \ + --env TF_VAR_os_distro_version=${DISTRO_VERSION} \ + --env TF_VAR_do_token=${env.TF_VAR_do_token} \ + --env TF_VAR_lh_aws_access_key=${AWS_ACCESS_KEY} \ + --env TF_VAR_lh_aws_instance_name_controlplane="${JOB_BASE_NAME}-ctrl" \ + --env TF_VAR_lh_aws_instance_name_worker="${JOB_BASE_NAME}-wrk" \ + --env TF_VAR_lh_aws_instance_type_controlplane=${CONTROLPLANE_INSTANCE_TYPE} \ + --env TF_VAR_lh_aws_instance_type_worker=${WORKER_INSTANCE_TYPE}\ + --env TF_VAR_lh_aws_secret_key=${AWS_SECRET_KEY} \ + --env TF_VAR_selinux_mode=${SELINUX_MODE} \ + --env TF_VAR_registration_code=${REGISTRATION_CODE} \ + --env TF_VAR_cis_hardening=${CIS_HARDENING} \ + ${imageName} + """ + } + + timeout(60) { + stage ('terraform') { + sh "docker exec ${JOB_BASE_NAME}-${BUILD_NUMBER} pipelines/utilities/terraform_setup.sh" + } + } + + stage ('longhorn setup & tests') { + sh "docker exec ${JOB_BASE_NAME}-${BUILD_NUMBER} pipelines/flux/scripts/longhorn-setup.sh" + } + + stage ('download support bundle') { + sh "docker exec ${JOB_BASE_NAME}-${BUILD_NUMBER} pipelines/utilities/download_support_bundle.sh ${JOB_BASE_NAME}-${BUILD_NUMBER}-bundle.zip" + sh "docker cp ${JOB_BASE_NAME}-${BUILD_NUMBER}:${WORKSPACE}/${JOB_BASE_NAME}-${BUILD_NUMBER}-bundle.zip ." + archiveArtifacts allowEmptyArchive: true, artifacts: '**/*.zip', followSymlinks: false + } + + stage ('report generation') { + sh "docker cp ${JOB_BASE_NAME}-${BUILD_NUMBER}:${WORKSPACE}/longhorn-test-junit-report.xml ." + + if(params.LONGHORN_UPGRADE_TEST && params.LONGHORN_TRANSIENT_VERSION) { + sh "docker cp ${JOB_BASE_NAME}-${BUILD_NUMBER}:${WORKSPACE}/longhorn-test-upgrade-from-stable-junit-report.xml ." + sh "docker cp ${JOB_BASE_NAME}-${BUILD_NUMBER}:${WORKSPACE}/longhorn-test-upgrade-from-transient-junit-report.xml ." + summary = junit 'longhorn-test-upgrade-from-stable-junit-report.xml, longhorn-test-upgrade-from-transient-junit-report.xml, longhorn-test-junit-report.xml' + } + else if(params.LONGHORN_UPGRADE_TEST) { + sh "docker cp ${JOB_BASE_NAME}-${BUILD_NUMBER}:${WORKSPACE}/longhorn-test-upgrade-from-stable-junit-report.xml ." + summary = junit 'longhorn-test-upgrade-from-stable-junit-report.xml, longhorn-test-junit-report.xml' + } + else { + summary = junit 'longhorn-test-junit-report.xml' + } + } + + } catch (e) { + currentBuild.result = "FAILED" + throw e + } finally { + stage ('releasing resources') { + if (sh (script: "docker container inspect airgap-${JOB_BASE_NAME}-${BUILD_NUMBER} > /dev/null 2>&1", returnStatus: true) == 0) { + sh "docker exec airgap-${JOB_BASE_NAME}-${BUILD_NUMBER} ./airgap/scripts/cleanup.sh" + sh "docker stop airgap-${JOB_BASE_NAME}-${BUILD_NUMBER}" + sh "docker rm -v airgap-${JOB_BASE_NAME}-${BUILD_NUMBER}" + sh "docker rmi airgap-${JOB_BASE_NAME}-${BUILD_NUMBER}" + } + + if (sh (script: "docker container inspect ${JOB_BASE_NAME}-${BUILD_NUMBER} > /dev/null 2>&1", returnStatus: true) == 0) { + sh "docker exec ${JOB_BASE_NAME}-${BUILD_NUMBER} pipelines/utilities/cleanup.sh" + sh "docker stop ${JOB_BASE_NAME}-${BUILD_NUMBER}" + sh "docker rm -v ${JOB_BASE_NAME}-${BUILD_NUMBER}" + sh "docker rmi ${imageName}" + } + + if (summary) { + summary_msg = "\nTest Summary - Failures: ${summary.failCount}, Skipped: ${summary.skipCount}, Passed: ${summary.passCount} -- Job completed in ${currentBuild.durationString.replace(' and counting', '')}" + } else { + summary_msg = "\n Test Failed: No Junit report" + } + + if(params.SEND_SLACK_NOTIFICATION){ + notifyBuild(currentBuild.result, summary_msg, params.NOTIFY_SLACK_CHANNEL) + } + } + } + } + +} + + +def notifyBuild(String buildStatus = 'STARTED', String summary_msg, String slack_channel) { + // build status of null means successful + buildStatus = buildStatus ?: 'SUCCESSFUL' + + // Default values + def colorName = 'RED' + def colorCode = '#FF0000' + def subject = "${buildStatus}: Job '${env.JOB_BASE_NAME} [${env.BUILD_NUMBER}]'" + def summary = "${subject} (${env.BUILD_URL})" + summary_msg + + // Override default values based on build status + if (buildStatus == 'STARTED') { + color = 'YELLOW' + colorCode = '#FFFF00' + } else if (buildStatus == 'SUCCESSFUL') { + color = 'GREEN' + colorCode = '#00FF00' + } else { + color = 'RED' + colorCode = '#FF0000' + } + + // Send notifications + slackSend (color: colorCode, message: summary, channel: slack_channel, tokenCredentialId: 'longhorn-tests-slack-token') +} diff --git a/pipelines/flux/scripts/build.sh b/pipelines/flux/scripts/build.sh new file mode 100755 index 0000000000..5a4f843824 --- /dev/null +++ b/pipelines/flux/scripts/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker build --no-cache -f ./pipelines/flux/Dockerfile.setup -t "${JOB_BASE_NAME}-${BUILD_NUMBER}" . diff --git a/pipelines/flux/scripts/longhorn-setup.sh b/pipelines/flux/scripts/longhorn-setup.sh new file mode 100755 index 0000000000..0bc39bbdea --- /dev/null +++ b/pipelines/flux/scripts/longhorn-setup.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +set -x + +source pipelines/utilities/kubeconfig.sh +source pipelines/utilities/selinux_workaround.sh +source pipelines/utilities/install_csi_snapshotter.sh +source pipelines/utilities/create_aws_secret.sh +source pipelines/utilities/install_backupstores.sh +source pipelines/utilities/create_longhorn_namespace.sh +source pipelines/utilities/flux.sh +source pipelines/utilities/run_longhorn_test.sh + +# create and clean tmpdir +TMPDIR="/tmp/longhorn" +mkdir -p ${TMPDIR} +rm -rf "${TMPDIR}/" + +export LONGHORN_NAMESPACE="longhorn-system" +export LONGHORN_INSTALL_METHOD="flux" +export HELM_CHART_DEFAULT_URL="https://charts.longhorn.io" + + +main(){ + set_kubeconfig + + if [[ ${DISTRO} == "rhel" ]] || [[ ${DISTRO} == "rockylinux" ]] || [[ ${DISTRO} == "oracle" ]]; then + apply_selinux_workaround + fi + + # set debugging mode off to avoid leaking aws secrets to the logs. + # DON'T REMOVE! + set +x + create_aws_secret + set -x + + create_longhorn_namespace + install_backupstores + install_csi_snapshotter + + init_flux + + if [[ "${LONGHORN_UPGRADE_TEST}" == true ]]; then + create_flux_helm_repo "${HELM_CHART_DEFAULT_URL}" + create_flux_helm_release "${LONGHORN_STABLE_VERSION}" + LONGHORN_UPGRADE_TYPE="from_stable" + LONGHORN_UPGRADE_TEST_POD_NAME="longhorn-test-upgrade-from-stable" + if [[ -n "${LONGHORN_TRANSIENT_VERSION}" ]]; then + FLUX_HELM_CHART_URL="${HELM_CHART_DEFAULT_URL}" + FLUX_HELM_CHART_VERSION="${LONGHORN_TRANSIENT_VERSION}" + UPGRADE_LH_ENGINE_IMAGE="longhornio/longhorn-engine:${LONGHORN_TRANSIENT_VERSION}" + run_longhorn_upgrade_test + LONGHORN_UPGRADE_TYPE="from_transient" + LONGHORN_UPGRADE_TEST_POD_NAME="longhorn-test-upgrade-from-transient" + fi + FLUX_HELM_CHART_URL="${HELM_CHART_URL}" + FLUX_HELM_CHART_VERSION="${LONGHORN_INSTALL_VERSION}" + UPGRADE_LH_ENGINE_IMAGE="longhornio/longhorn-engine:${LONGHORN_INSTALL_VERSION}" + run_longhorn_upgrade_test + run_longhorn_test + else + create_flux_helm_repo "${HELM_CHART_URL}" + create_flux_helm_release "${LONGHORN_INSTALL_VERSION}" + run_longhorn_test + fi +} + +main diff --git a/pipelines/flux/scripts/upgrade-longhorn.sh b/pipelines/flux/scripts/upgrade-longhorn.sh new file mode 100755 index 0000000000..95056e032a --- /dev/null +++ b/pipelines/flux/scripts/upgrade-longhorn.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -x + +export HELM_CHART_URL="${1}" +export HELM_CHART_VERSION="${2}" + +source pipelines/utilities/flux.sh + +export LONGHORN_NAMESPACE="longhorn-system" + +create_flux_helm_repo "${HELM_CHART_URL}" +create_flux_helm_release "${HELM_CHART_VERSION}" diff --git a/pipelines/utilities/flux.sh b/pipelines/utilities/flux.sh new file mode 100755 index 0000000000..18d6312bb9 --- /dev/null +++ b/pipelines/utilities/flux.sh @@ -0,0 +1,19 @@ +source pipelines/utilities/longhorn_status.sh + + +init_flux(){ + flux install +} + + +create_flux_helm_repo(){ + CHART_URL="${1:-${HELM_CHART_URL}}" + flux create source helm longhorn --url "${CHART_URL}" --namespace "${LONGHORN_NAMESPACE}" +} + + +create_flux_helm_release(){ + CHART_VERSION="${1:-${HELM_CHART_VERSION}}" + flux create helmrelease longhorn --chart longhorn --source HelmRepository/longhorn --chart-version "${CHART_VERSION}" --namespace "${LONGHORN_NAMESPACE}" + wait_longhorn_status_running +} \ No newline at end of file diff --git a/pipelines/utilities/run_longhorn_test.sh b/pipelines/utilities/run_longhorn_test.sh index 0122434a47..1bd684dea0 100755 --- a/pipelines/utilities/run_longhorn_test.sh +++ b/pipelines/utilities/run_longhorn_test.sh @@ -79,6 +79,8 @@ run_longhorn_upgrade_test(){ "--include-upgrade-test", "-k", "test_upgrade", "--lh-install-method", "'${LONGHORN_INSTALL_METHOD}'", + "--flux-helm-chart-url", "'${FLUX_HELM_CHART_URL}'", + "--flux-helm-chart-version", "'${FLUX_HELM_CHART_VERSION}'", "--rancher-hostname", "'${RANCHER_HOSTNAME}'", "--rancher-access-key", "'${RANCHER_ACCESS_KEY}'", "--rancher-secret-key", "'${RANCHER_SECRET_KEY}'",