From 9a2c3acda9b51e1632095af8f940c74fd9102df4 Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Mon, 10 Nov 2025 14:32:53 +0100 Subject: [PATCH] update-strategy tests --- .github/workflows/gha-e2e-tests.yaml | 30 +++- .../update-strategy.test.sh | 143 ++++++++++++++++++ 2 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 test/actions.github.com/update-strategy.test.sh diff --git a/.github/workflows/gha-e2e-tests.yaml b/.github/workflows/gha-e2e-tests.yaml index ad0cd646..52a8afee 100644 --- a/.github/workflows/gha-e2e-tests.yaml +++ b/.github/workflows/gha-e2e-tests.yaml @@ -146,7 +146,6 @@ jobs: timeout-minutes: 20 if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.id == github.repository_id env: - WORKFLOW_FILE: arc-test-dind-workflow.yaml TARGET_ORG: ${{ env.TARGET_ORG }} TARGET_REPO: ${{ env.TARGET_REPO }} @@ -265,7 +264,6 @@ jobs: timeout-minutes: 20 if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.id == github.repository_id env: - WORKFLOW_FILE: arc-test-dind-workflow.yaml TARGET_ORG: ${{ env.TARGET_ORG }} TARGET_REPO: ${{ env.TARGET_REPO }} @@ -383,7 +381,6 @@ jobs: timeout-minutes: 20 if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.id == github.repository_id env: - WORKFLOW_FILE: arc-test-dind-workflow.yaml TARGET_ORG: ${{ env.TARGET_ORG }} TARGET_REPO: ${{ env.TARGET_REPO }} @@ -510,7 +507,6 @@ jobs: timeout-minutes: 20 if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.id == github.repository_id env: - WORKFLOW_FILE: arc-test-dind-workflow.yaml TARGET_ORG: ${{ env.TARGET_ORG }} TARGET_REPO: ${{ env.TARGET_REPO }} @@ -639,7 +635,6 @@ jobs: timeout-minutes: 20 if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.id == github.repository_id env: - WORKFLOW_FILE: arc-test-dind-workflow.yaml TARGET_ORG: ${{ env.TARGET_ORG }} TARGET_REPO: ${{ env.TARGET_REPO }} @@ -879,6 +874,31 @@ jobs: arc-namespace: "arc-runners" arc-controller-namespace: "arc-systems" + update-strategy-tests-v2: + runs-on: ubuntu-latest + timeout-minutes: 20 + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.id == github.repository_id + env: + TARGET_ORG: ${{ env.TARGET_ORG }} + TARGET_REPO: ${{ env.TARGET_REPO }} + + steps: + - uses: actions/checkout@v5 + with: + ref: ${{github.head_ref}} + + - name: Get configure token + id: config-token + uses: peter-murray/workflow-application-token-action@dc0413987a085fa17d19df9e47d4677cf81ffef3 + with: + application_id: ${{ secrets.E2E_TESTS_ACCESS_APP_ID }} + application_private_key: ${{ secrets.E2E_TESTS_ACCESS_PK }} + organization: ${{ env.TARGET_ORG }} + + - name: Run default setup test + run: hack/e2e-test.sh update-strategy + shell: bash + update-strategy-tests: runs-on: ubuntu-latest timeout-minutes: 20 diff --git a/test/actions.github.com/update-strategy.test.sh b/test/actions.github.com/update-strategy.test.sh new file mode 100644 index 00000000..bdc213d9 --- /dev/null +++ b/test/actions.github.com/update-strategy.test.sh @@ -0,0 +1,143 @@ +#!/bin/bash + +set -euo pipefail + +DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" + +ROOT_DIR="$(realpath "${DIR}/../..")" + +source "${DIR}/helper.sh" || { echo "Failed to source helper.sh"; exit 1; } + +SCALE_SET_NAME="update-strategy-$(date '+%M%S')$((($RANDOM + 100) % 100 + 1))" +SCALE_SET_NAMESPACE="arc-runners" +WORKFLOW_FILE="arc-test-sleepy-matrix.yaml" +ARC_NAME="arc" +ARC_NAMESPACE="arc-systems" + +function install_arc() { + echo "Installing ARC" + + helm install "${ARC_NAME}" \ + --namespace "${ARC_NAMESPACE}" \ + --create-namespace \ + --set image.repository="${IMAGE_NAME}" \ + --set image.tag="${IMAGE_TAG}" \ + --set flags.updateStrategy="eventual" \ + "${ROOT_DIR}/charts/gha-runner-scale-set-controller" \ + --debug + + if ! NAME="${ARC_NAME}" NAMESPACE="${ARC_NAMESPACE}" wait_for_arc; then + NAMESPACE="${ARC_NAMESPACE}" log_arc + return 1 + fi +} + +function install_scale_set() { + echo "Installing scale set ${SCALE_SET_NAME}/${SCALE_SET_NAMESPACE}" + helm install "${SCALE_SET_NAME}" \ + --namespace "${SCALE_SET_NAMESPACE}" \ + --create-namespace \ + --set githubConfigUrl="https://github.com/${TARGET_ORG}/${TARGET_REPO}" \ + --set githubConfigSecret.github_token="${GITHUB_TOKEN}" \ + "${ROOT_DIR}/charts/gha-runner-scale-set" \ + --debug + + if ! NAME="${SCALE_SET_NAME}" NAMESPACE="${ARC_NAMESPACE}" wait_for_scale_set; then + NAMESPACE="${ARC_NAMESPACE}" log_arc + return 1 + fi +} + +function upgrade_scale_set() { + echo "Upgrading scale set ${SCALE_SET_NAME}/${SCALE_SET_NAMESPACE}" + helm upgrade "${SCALE_SET_NAME}" \ + --namespace "${SCALE_SET_NAMESPACE}" \ + --set githubConfigUrl="https://github.com/${TARGET_ORG}/${TARGET_REPO}" \ + --set githubConfigSecret.github_token="${GITHUB_TOKEN}" \ + --set template.spec.containers[0].name="runner" \ + --set template.spec.containers[0].image="ghcr.io/actions/actions-runner:latest" \ + --set template.spec.containers[0].command={"/home/runner/run.sh"} \ + --set template.spec.containers[0].env[0].name="TEST" \ + --set template.spec.containers[0].env[0].value="E2E TESTS" \ + "${ROOT_DIR}/charts/gha-runner-scale-set" \ + --version="${VERSION}" \ + --debug + +} + +function assert_listener_deleted() { + local count=0 + while true; do + LISTENER_COUNT="$(kubectl get pods -l actions.github.com/scale-set-name="${SCALE_SET_NAME}" -n "${ARC_NAMESPACE}" --field-selector=status.phase=Running -o=jsonpath='{.items}' | jq 'length')" + RUNNERS_COUNT="$(kubectl get pods -l app.kubernetes.io/component=runner -n "${SCALE_SET_NAMESPACE}" --field-selector=status.phase=Running -o=jsonpath='{.items}' | jq 'length')" + RESOURCES="$(kubectl get pods -A)" + + if [ "${LISTENER_COUNT}" -eq 0 ]; then + echo "Listener has been deleted" + echo "${RESOURCES}" + return 0 + fi + if [ "${count}" -ge 60 ]; then + echo "Timeout waiting for listener to be deleted" + echo "${RESOURCES}" + return 1 + fi + + echo "Waiting for listener to be deleted" + echo "Listener count: ${LISTENER_COUNT} target: 0 | Runners count: ${RUNNERS_COUNT} target: 3" + + sleep 1 + count=$((count+1)) + done +} + +function assert_listener_recreated() { + count=0 + while true; do + LISTENER_COUNT="$(kubectl get pods -l actions.github.com/scale-set-name="${SCALE_SET_NAME}" -n "${ARC_NAMESPACE}" --field-selector=status.phase=Running -o=jsonpath='{.items}' | jq 'length')" + RUNNERS_COUNT="$(kubectl get pods -l app.kubernetes.io/component=runner -n "${SCALE_SET_NAMESPACE}" --field-selector=status.phase=Running -o=jsonpath='{.items}' | jq 'length')" + RESOURCES="$(kubectl get pods -A)" + + if [ "${LISTENER_COUNT}" -eq 1 ]; then + echo "Listener is up!" + echo "${RESOURCES}" + exit 0 + fi + if [ "${count}" -ge 120 ]; then + echo "Timeout waiting for listener to be recreated" + echo "${RESOURCES}" + exit 1 + fi + + echo "Waiting for listener to be recreated" + echo "Listener count: ${LISTENER_COUNT} target: 1 | Runners count: ${RUNNERS_COUNT} target: 0" + + sleep 1 + count=$((count+1)) + done +} + +function main() { + local failed=() + + build_image + create_cluster + install_arc + install_scale_set + + WORKFLOW_FILE="${WORKFLOW_FILE}" SCALE_SET_NAME="${SCALE_SET_NAME}" run_workflow || failed+=("run_workflow") + + upgrade_scale_set || failed+=("upgrade_scale_set") + assert_listener_deleted || failed+=("assert_listener_deleted") + assert_listener_recreated || failed+=("assert_listener_recreated") + + INSTALLATION_NAME="${SCALE_SET_NAME}" NAMESPACE="${SCALE_SET_NAMESPACE}" cleanup_scale_set || failed+=("cleanup_scale_set") + + NAMESPACE="${ARC_NAMESPACE}" arc_logs + + delete_cluster + + print_results "${failed[@]}" +} + +main