From 74cb2a119f5fcb736a406586090ef18261933ae0 Mon Sep 17 00:00:00 2001 From: Mansur Uralov Date: Wed, 31 Jan 2024 10:06:13 +0100 Subject: [PATCH] Create Upgrade jobs for PR and main merge (#401) * Create e2e test upgrade job * Job tests upgrade from main branch to the current PR version * Use different MANAGER images for PR and main branch tests * Use reusable GH wokrflow * Use for PR ugprade job * Use for main merge upgrade job * Use resulable wokflow for release push job Upgrade test from the latest to release to main commit uses reusable workflow * Test push job with push event * Debug Get release tag job * Use current PR branch * Use curl directly * Improve reusable workflow * Use only docker tags * Identify dev repo with PR tag * Set default values to branches * Use image if branch name is not set * Don't checkout PR branh as it is already done * Use image tag as branches * Rename reusable job and reconfigure push job * Improve review comments * Rename reusable workflow file name --- .../workflows/e2e-upgrade-test-reusable.yaml | 110 ++++++++++++++++++ .github/workflows/pull-e2e-upgrade-test.yaml | 19 +++ .github/workflows/push-e2e-upgrade-test.yaml | 33 ++++++ hack/ci/build-full-image-path.sh | 16 +++ 4 files changed, 178 insertions(+) create mode 100644 .github/workflows/e2e-upgrade-test-reusable.yaml create mode 100644 .github/workflows/pull-e2e-upgrade-test.yaml create mode 100644 .github/workflows/push-e2e-upgrade-test.yaml create mode 100755 hack/ci/build-full-image-path.sh diff --git a/.github/workflows/e2e-upgrade-test-reusable.yaml b/.github/workflows/e2e-upgrade-test-reusable.yaml new file mode 100644 index 00000000..e17ff701 --- /dev/null +++ b/.github/workflows/e2e-upgrade-test-reusable.yaml @@ -0,0 +1,110 @@ +name: Upgrade Tests Workflow (reusable) + +env: + E2E_LOG_LEVEL: debug + KYMA_STABILITY: "unstable" + KYMA: "./hack/kyma" + +on: + workflow_call: + inputs: + # image tag before upgrade + pre-upgrade-image-tag: + required: true + type: string + # image tag after upgrade + post-upgrade-image-tag: + required: true + type: string + # job name of the prow build job + build-job-name: + type: string + # commit sha of the PR or main branch commit + build-job-commit-sha: + type: string + +jobs: + e2e-upgrade: # This job tests the upgrade of Eventing module from the latest image of the main branch to the current commit. + runs-on: ubuntu-latest + env: + BACKEND_TYPE: NATS + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Pre-upgrade checkout + run: git checkout -b ${{ inputs.pre-upgrade-image-tag }} + + - name: Install k3d tools + run: make -C hack/ci/ install-k3d-tools + + - name: Install Kyma CLI & setup k3d cluster using Kyma CLI + run: | + make kyma + make -C hack/ci/ create-k3d + kubectl version + kubectl cluster-info + + - name: Create kyma-system namespace + run: | + make -C hack/ci/ create-kyma-system-ns + + - name: Install the latest released NATS manager + run: | + kubectl apply -f https://github.com/kyma-project/nats-manager/releases/latest/download/nats-manager.yaml + kubectl apply -f https://github.com/kyma-project/nats-manager/releases/latest/download/nats-default-cr.yaml + + - name: Wait for NATS module to be ready + run: | + make -C hack/ci/ wait-nats-cr-ready + + - name: Install Eventing manager before upgrade + run: | + pre_upgrade_image=$(./hack/ci/build-full-image-path.sh ${{ inputs.pre-upgrade-image-tag }}) + echo "Pre-upgrade image: $pre_upgrade_image" + make deploy IMG=$pre_upgrade_image + + - name: Create test resources and wait for eventing CR readiness + run: | + export MANAGER_IMAGE=$(./hack/ci/build-full-image-path.sh ${{ inputs.pre-upgrade-image-tag }}) + make e2e-setup + make e2e-eventing-setup + + - name: Wait for the ${{ inputs.build-job-name }} job to succeed + if: ${{ inputs.build-job-name != '' }} + uses: kyma-project/wait-for-commit-status-action@2b3ffe09af8b6f40e1213d5fb7f91a7bd41ffb20 + with: + context: ${{ inputs.build-job-name }} + commit_ref: "${{ inputs.build-job-commit-sha }}" # Note: 'github.event.pull_request.head.sha' is not same as 'github.sha' on pull requests. + timeout: 600000 # 10 minutes in milliseconds + # The check interval is kept long otherwise it will exhaust the GitHub rate limit (More info: https://docs.github.com/en/rest/overview/resources-in-the-rest-api?apiVersion=2022-11-28#rate-limiting) + check_interval: 60000 # 1 minute in milliseconds + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_OWNER: "${{ github.repository_owner }}" + GITHUB_REPO: "eventing-manager" + + - name: Checkout + uses: actions/checkout@v4 + - name: Post-upgrade checkout + run: git checkout -b ${{ inputs.post-upgrade-image-tag }} + + - name: Install Eventing manager after upgrade + run: | + post_upgrade_image=$(./hack/ci/build-full-image-path.sh ${{ inputs.post-upgrade-image-tag }}) + echo "Post-upgrade image: $post_upgrade_image" + make deploy IMG=$post_upgrade_image + + - name: Create test resources and waits for eventing CR readiness + run: | + export MANAGER_IMAGE=$(./hack/ci/build-full-image-path.sh ${{ inputs.post-upgrade-image-tag }}) + make e2e-setup + + - name: Run e2e tests + run: | + make e2e-eventing + + - name: Cleanup test resources + run: | + make e2e-eventing-cleanup + make e2e-cleanup + diff --git a/.github/workflows/pull-e2e-upgrade-test.yaml b/.github/workflows/pull-e2e-upgrade-test.yaml new file mode 100644 index 00000000..8a577b59 --- /dev/null +++ b/.github/workflows/pull-e2e-upgrade-test.yaml @@ -0,0 +1,19 @@ +name: pull-e2e-upgrade-test + +on: + pull_request: + branches: [ "main" ] + paths-ignore: + - 'docs/**' + - '**.md' + - 'sec-scanners-config.yaml' + +jobs: + upgrade-test: + uses: ./.github/workflows/e2e-upgrade-test-reusable.yaml + with: + pre-upgrade-image-tag: main + post-upgrade-image-tag: PR-${{ github.event.number }} + build-job-name: pull-eventing-manager-build + build-job-commit-sha: ${{ github.event.pull_request.head.sha }} + secrets: inherit diff --git a/.github/workflows/push-e2e-upgrade-test.yaml b/.github/workflows/push-e2e-upgrade-test.yaml new file mode 100644 index 00000000..99d3763d --- /dev/null +++ b/.github/workflows/push-e2e-upgrade-test.yaml @@ -0,0 +1,33 @@ +name: post-e2e-upgrade-test + +on: + push: + branches: [ "main" ] + paths-ignore: + - 'docs/**' + - '**.md' + - 'sec-scanners-config.yaml' + +jobs: + get-latest-release: + runs-on: ubuntu-latest + outputs: + latest_release_tag: ${{ steps.get-latest-release-tag.outputs.latest_release_tag }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get latest release tag + id: get-latest-release-tag + run: | + echo "latest_release_tag=$(curl -s https://api.github.com/repos/kyma-project/eventing-manager/releases/latest | jq -r '.tag_name')" >> "$GITHUB_OUTPUT" + + upgrade-test: + uses: ./.github/workflows/e2e-upgrade-test-reusable.yaml + needs: get-latest-release + with: + pre-upgrade-image-tag: ${{ needs.get-latest-release.outputs.latest_release_tag }} + post-upgrade-image-tag: main + build-job-name: push-eventing-manager-build + build-job-commit-sha: ${{ github.sha }} + secrets: inherit diff --git a/hack/ci/build-full-image-path.sh b/hack/ci/build-full-image-path.sh new file mode 100755 index 00000000..27e09474 --- /dev/null +++ b/hack/ci/build-full-image-path.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# builds full image path given dev and prod image repos and tag. If tag starts with PR, then it's a dev image. + +DOCKER_IMAGE_REPO=europe-docker.pkg.dev/kyma-project/prod/eventing-manager +DOCKER_IMAGE_REPO_DEV=europe-docker.pkg.dev/kyma-project/dev/eventing-manager + +image_tag=$1 + +if [[ $image_tag == PR* ]]; then + full_image_path=$DOCKER_IMAGE_REPO_DEV:$image_tag +else + full_image_path=$DOCKER_IMAGE_REPO:$image_tag +fi + +echo $full_image_path