Initial setup on test files and helper

This commit is contained in:
Nikola Jokic 2023-10-27 14:41:34 +02:00
parent 0bfa57ac50
commit b3d135408f
No known key found for this signature in database
GPG Key ID: 1115F751E6A09850
3 changed files with 192 additions and 0 deletions

19
hack/e2e-test.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/bash
DIR="$(dirname "${BASH_SOURCE[0]}")"
DIR="$(realpath "${DIR}")"
TEST_DIR="$(realpath "${DIR}/../test/actions.github.com")"
TARGETS=()
function set_targets() {
local cases="$(find "${TEST_DIR}" -name '*.test.sh' | sort | sed -e 's/\(.*\)/test_\1\.sh/')"
mapfile -t TARGETS < <(echo "${cases}")
echo $TARGETS
}
set_targets

View File

@ -0,0 +1,72 @@
#!/bin/bash
DIR="$(dirname "${BASH_SOURCE[0]}")"
DIR="$(realpath "${DIR}")"
ROOT_DIR="$(relpath "${DIR}/../..")"
source "${DIR}/helper.sh"
SCALE_SET_NAME="default-$(date + '%M%S')$(((${RANDOM} + 100) % 100 + 1))"
SCALE_SET_NAMESPACE="arc-runners"
WORKFLOW_FILE="arc-test-workflow.yaml"
function install_scale_set() {
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
NAME="${SCALE_SET_NAME}" NAMESPACE="${SCALE_SET_NAMESPACE}" wait_for_scale_set
}
function run_workflow() {
gh workflow run -R "${TARGET_ORG}/${TARGET_REPO}" "${WORKFLOW_FILE}"
local count=0
while true; do
STATUS=$(gh run list -R "${TARGET_ORG}/${TARGET_REPO}" --limit 1 --limit 1 --json status --jq '.[0].status')
if [ "${STATUS}" != "completed" ]; then
sleep 30
count=$((count + 1))
continue
fi
CONCLUSION=$(gh run list -R "${TARGET_ORG}/${TARGET_REPO}" --limit 1 --limit 1 --json conclusion --jq '.[0].conclusion')
if [[ "${CONCLUSION}" != "success" ]]; then
echo "Workflow failed"
return 1
fi
return 0
done
}
function main() {
local failed=()
build_image
create_cluster
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")
if [[ "${#failed[@]}" -ne 0 ]]; then
echo "----------------------------------"
echo "The following tests failed:"
for test in "${failed[@]}"; do
echo " - ${test}"
done
exit 1
fi
}
main

View File

@ -0,0 +1,101 @@
#!/bin/bash
DIR="$(dirname "${BASH_SOURCE[0]}")"
DIR="$(realpath "${DIR}")"
ROOT_DIR="$(relpath "${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")}"
function build_image() {
echo "Building ARC image"
cd ${ROOT_DIR}
export DOCKER_CLI_EXPERIMENTAL=enabled
export DOCKER_BUILDKIT=1
docker buildx build --platform ${PLATFORMS} \
--build-arg RUNNER_VERSION=${RUNNER_VERSION} \
--build-arg DOCKER_VERSION=${DOCKER_VERSION} \
--build-arg VERSION=${VERSION} \
--build-arg COMMIT_SHA=${COMMIT_SHA} \
-t "${DOCKER_IMAGE_NAME}:${VERSION}" \
-f Dockerfile \
. --load
cd -
}
function create_cluster() {
echo "Deleting minikube cluster if exists"
minikube delete || true
echo "Creating minikube cluster"
minikube start
echo "Loading image into minikube cluster"
minikube image load ${IMAGE}
}
function install_arc() {
echo "Installing ARC"
helm install ${INSTALLATION_NAME} \
--namespace ${NAMESPACE} \
--create-namespace \
--set image.repository=${IMAGE_NAME} \
--set image.tag=${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)
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
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
}
function wait_for_scale_set() {
local count=0
while true; do
POD_NAME=$(kubectl get pods -n ${NAMESPACE} -l actions.github.com/scale-set-name=${NAME} -o name)
if [ -n "$POD_NAME" ]; then
echo "Pod found: ${POD_NAME}"
break
fi
if [ "$count" -ge 60 ]; then
echo "Timeout waiting for listener pod with label actions.github.com/scale-set-name=${NAME}"
exit 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
}
function cleanup_scale_set() {
helm uninstall "${INSTALLATION_NAME}" --namespace "${NAMESPACE}" --debug
kubectl wait --timeout=10s --for=delete AutoScalingRunnerSet -n "${NAMESPACE}" -l app.kubernetes.io/instance="${INSTALLATION_NAME}" --ignore-not-found
}