From a9eb5b6c45b804d6279e257cc8e10c8a9173e97e Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Mon, 6 Nov 2023 14:20:05 +0100 Subject: [PATCH] Include tests for default_setup --- Makefile | 4 ++ hack/e2e-test.sh | 39 +++++++++++++++++- test/actions.github.com/default_setup.test.sh | 22 ++++++---- test/actions.github.com/helper.sh | 40 ++++++++++++------- 4 files changed, 83 insertions(+), 22 deletions(-) mode change 100644 => 100755 hack/e2e-test.sh mode change 100644 => 100755 test/actions.github.com/default_setup.test.sh diff --git a/Makefile b/Makefile index 2d4a9a9a..3972803c 100644 --- a/Makefile +++ b/Makefile @@ -300,6 +300,10 @@ acceptance/runner/startup: e2e: go test -count=1 -v -timeout 600s -run '^TestE2E$$' ./test/e2e +.PHONY: e2e-gha +e2e-gha: + bash hack/e2e-test.sh + # Upload release file to GitHub. github-release: release ghr ${VERSION} release/ diff --git a/hack/e2e-test.sh b/hack/e2e-test.sh old mode 100644 new mode 100755 index 0853a102..e439f34b --- a/hack/e2e-test.sh +++ b/hack/e2e-test.sh @@ -6,14 +6,51 @@ DIR="$(realpath "${DIR}")" TEST_DIR="$(realpath "${DIR}/../test/actions.github.com")" +export PLATFORMS="linux/amd64" + TARGETS=() function set_targets() { - local cases="$(find "${TEST_DIR}" -name '*.test.sh' | sort | sed -e 's/\(.*\)/test_\1\.sh/')" + local cases="$(find "${TEST_DIR}" -name '*.test.sh' | sed "s#^${TEST_DIR}/##g" )" mapfile -t TARGETS < <(echo "${cases}") echo $TARGETS } +function main() { + local failed=() + + for target in "${TARGETS[@]}"; do + echo "============================================================" + test="${TEST_DIR}/${target}" + if [[ ! -x "${test}" ]]; then + echo "Error: test ${test} is not executable or not found" + failed+=("${test}") + continue + fi + + echo "Running test ${target}" + if ! "${test}"; then + failed+=("${target}") + echo "---------------------------------" + echo "FAILED: ${target}" + else + echo "---------------------------------" + echo "PASSED: ${target}" + fi + echo "============================================================" + done + + if [[ "${#failed[@]}" -gt 0 ]]; then + echo "Failed tests:" + for fail in "${failed[@]}"; do + echo " ${fail}" + done + exit 1 + fi +} + set_targets + +main diff --git a/test/actions.github.com/default_setup.test.sh b/test/actions.github.com/default_setup.test.sh old mode 100644 new mode 100755 index f2f93ae7..ea98bb08 --- a/test/actions.github.com/default_setup.test.sh +++ b/test/actions.github.com/default_setup.test.sh @@ -4,25 +4,31 @@ DIR="$(dirname "${BASH_SOURCE[0]}")" DIR="$(realpath "${DIR}")" -ROOT_DIR="$(relpath "${DIR}/../..")" +ROOT_DIR="$(realpath "${DIR}/../..")" source "${DIR}/helper.sh" -SCALE_SET_NAME="default-$(date + '%M%S')$(((${RANDOM} + 100) % 100 + 1))" +SCALE_SET_NAME="default-$(date +'%M%S')$(((${RANDOM} + 100) % 100 + 1))" SCALE_SET_NAMESPACE="arc-runners" WORKFLOW_FILE="arc-test-workflow.yaml" - +ARC_NAME="arc" +ARC_NAMESPACE="arc-systems" function install_scale_set() { + echo "Installing scale set ${SCALE_SET_NAMESPACE}/${SCALE_SET_NAME}" 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 \ + --version="${VERSION}" \ --debug - NAME="${SCALE_SET_NAME}" NAMESPACE="${SCALE_SET_NAMESPACE}" wait_for_scale_set + if ! NAME="${SCALE_SET_NAME}" NAMESPACE="${ARC_NAMESPACE}" wait_for_scale_set; then + NAMESPACE="${ARC_NAMESPACE}" log_arc + return 1 + fi } function run_workflow() { @@ -52,20 +58,22 @@ function main() { build_image create_cluster - install_arc + + NAME="${ARC_NAME}" NAMESPACE="${ARC_NAMESPACE}" install_arc install_scale_set || failed+=("install_scale_set") run_workflow || failed+=("run_workflow") INSTALLATION_NAME="${SCALE_SET_NAME}" NAMESPACE="${SCALE_SET_NAMESPACE}" cleanup_scale_set || failed+=("cleanup_scale_set") + delete_cluster + if [[ "${#failed[@]}" -ne 0 ]]; then echo "----------------------------------" echo "The following tests failed:" for test in "${failed[@]}"; do echo " - ${test}" done - - exit 1 + return 1 fi } diff --git a/test/actions.github.com/helper.sh b/test/actions.github.com/helper.sh index 11f03abd..4356db4e 100644 --- a/test/actions.github.com/helper.sh +++ b/test/actions.github.com/helper.sh @@ -4,15 +4,16 @@ DIR="$(dirname "${BASH_SOURCE[0]}")" DIR="$(realpath "${DIR}")" -ROOT_DIR="$(relpath "${DIR}/../..")" +ROOT_DIR="$(realpath "${DIR}/../..")" export TARGET_ORG="${TARGET_ORG:-actions-runner-controller}" export TARGET_REPO="${TARGET_REPO:-arc_e2e_test_dummy}" export IMAGE_NAME="${IMAGE_NAME:-arc-test-image}" -export IMAGE_VERSION="${IMAGE_VERSION:-$(yq .version < "${ROOT_DIR}/gha-runner-scale-set-controller/Chart.yaml")}" +export VERSION="${VERSION:-$(yq .version < "${ROOT_DIR}/charts/gha-runner-scale-set-controller/Chart.yaml")}" +export IMAGE_VERSION="${IMAGE_VERSION:-${VERSION}}" function build_image() { - echo "Building ARC image" + echo "Building ARC image ${IMAGE_NAME}:${IMAGE_VERSION}" cd ${ROOT_DIR} @@ -23,10 +24,11 @@ function build_image() { --build-arg DOCKER_VERSION=${DOCKER_VERSION} \ --build-arg VERSION=${VERSION} \ --build-arg COMMIT_SHA=${COMMIT_SHA} \ - -t "${DOCKER_IMAGE_NAME}:${VERSION}" \ + -t "${IMAGE_NAME}:${IMAGE_VERSION}" \ -f Dockerfile \ . --load + echo "Created image ${IMAGE_NAME}:${IMAGE_VERSION}" cd - } @@ -38,39 +40,49 @@ function create_cluster() { minikube start echo "Loading image into minikube cluster" - minikube image load ${IMAGE} + minikube image load "${IMAGE_NAME}:${IMAGE_VERSION}" +} + +function delete_cluster() { + echo "Deleting minikube cluster" + minikube delete } function install_arc() { echo "Installing ARC" - helm install ${INSTALLATION_NAME} \ + helm install ${NAME} \ --namespace ${NAMESPACE} \ --create-namespace \ --set image.repository=${IMAGE_NAME} \ - --set image.tag=${VERSION} \ + --set image.tag=${IMAGE_VERSION} \ ${ROOT_DIR}/charts/gha-runner-scale-set-controller \ --debug echo "Waiting for ARC to be ready" local count=0; while true; do - POD_NAME=$(kubectl get pods -n arc-systems -l app.kubernetes.io/name=gha-rs-controller -o name) + POD_NAME=$(kubectl get pods -n ${NAMESPACE} -l app.kubernetes.io/name=gha-rs-controller -o name) if [ -n "$POD_NAME" ]; then echo "Pod found: $POD_NAME" break fi if [ "$count" -ge 60 ]; then echo "Timeout waiting for controller pod with label app.kubernetes.io/name=gha-rs-controller" - exit 1 + return 1 fi sleep 1 count=$((count+1)) done - kubectl wait --timeout=30s --for=condition=ready pod -n arc-systems -l app.kubernetes.io/name=gha-rs-controller - kubectl get pod -n arc-systems - kubectl describe deployment arc-gha-rs-controller -n arc-systems + kubectl wait --timeout=30s --for=condition=ready pod -n "${NAMESPACE}" -l app.kubernetes.io/name=gha-rs-controller + kubectl get pod -n "${NAMESPACE}" + kubectl describe deployment "${NAME}" -n "${NAMESPACE}" +} + +function log_arc() { + echo "ARC logs" + kubectl logs -n "${NAMESPACE}" -l app.kubernetes.io/name=gha-rs-controller } function wait_for_scale_set() { @@ -84,14 +96,14 @@ function wait_for_scale_set() { if [ "$count" -ge 60 ]; then echo "Timeout waiting for listener pod with label actions.github.com/scale-set-name=${NAME}" - exit 1 + return 1 fi sleep 1 count=$((count+1)) done kubectl wait --timeout=30s --for=condition=ready pod -n ${NAMESPACE} -l actions.github.com/scale-set-name=${NAME} - kubectl get pod -n arc-systems + kubectl get pod -n ${NAMESPACE} } function cleanup_scale_set() {