diff --git a/Makefile b/Makefile index 1a182b51a3..af9c28cb3b 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,8 @@ VERSION ?= latest RUNNER_NAME ?= ${DOCKER_USER}/actions-runner RUNNER_TAG ?= ${VERSION} TEST_REPO ?= ${DOCKER_USER}/actions-runner-controller +TEST_ORG ?= +TEST_ORG_REPO ?= SYNC_PERIOD ?= 5m # From https://github.com/VictoriaMetrics/operator/pull/44 @@ -156,7 +158,7 @@ acceptance: release/clean acceptance/pull docker-build release acceptance/run: acceptance/kind acceptance/load acceptance/setup acceptance/deploy acceptance/tests acceptance/teardown acceptance/kind: - kind create cluster --name acceptance + kind create cluster --name acceptance --config acceptance/kind.yaml # Set TMPDIR to somewhere under $HOME when you use docker installed with Ubuntu snap # Otherwise `load docker-image` fail while running `docker save`. @@ -192,7 +194,9 @@ acceptance/teardown: kind delete cluster --name acceptance acceptance/deploy: - NAME=${NAME} DOCKER_USER=${DOCKER_USER} VERSION=${VERSION} RUNNER_NAME=${RUNNER_NAME} RUNNER_TAG=${RUNNER_TAG} TEST_REPO=${TEST_REPO} acceptance/deploy.sh + NAME=${NAME} DOCKER_USER=${DOCKER_USER} VERSION=${VERSION} RUNNER_NAME=${RUNNER_NAME} RUNNER_TAG=${RUNNER_TAG} TEST_REPO=${TEST_REPO} \ + TEST_ORG=${TEST_ORG} TEST_ORG_REPO=${TEST_ORG_REPO} \ + acceptance/deploy.sh acceptance/tests: acceptance/checks.sh diff --git a/acceptance/deploy.sh b/acceptance/deploy.sh index b9aca1bdca..64554e3b64 100755 --- a/acceptance/deploy.sh +++ b/acceptance/deploy.sh @@ -4,6 +4,8 @@ set -e tpe=${ACCEPTANCE_TEST_SECRET_TYPE} +VALUES_FILE=${VALUES_FILE:-$(dirname $0)/values.yaml} + if [ "${tpe}" == "token" ]; then if ! kubectl get secret controller-manager -n actions-runner-system >/dev/null; then kubectl create secret generic controller-manager \ @@ -31,7 +33,8 @@ if [ "${tool}" == "helm" ]; then --set syncPeriod=${SYNC_PERIOD} \ --set authSecret.create=false \ --set image.repository=${NAME} \ - --set image.tag=${VERSION} + --set image.tag=${VERSION} \ + -f ${VALUES_FILE} kubectl -n actions-runner-system wait deploy/actions-runner-controller --for condition=available --timeout 60s else kubectl apply \ @@ -43,4 +46,21 @@ fi # Adhocly wait for some time until actions-runner-controller's admission webhook gets ready sleep 20 -cat acceptance/testdata/runnerdeploy.yaml | envsubst | kubectl apply -f - +if [ -n "${TEST_REPO}" ]; then + cat acceptance/testdata/runnerdeploy.yaml | envsubst | kubectl apply -f - + cat acceptance/testdata/hra.yaml | envsubst | kubectl apply -f - +else + echo 'Skipped deploying runnerdeployment and hra. Set TEST_REPO to "yourorg/yourrepo" to deploy.' +fi + +if [ -n "${TEST_ORG}" ]; then + cat acceptance/testdata/org.runnerdeploy.yaml | envsubst | kubectl apply -f - + + if [ -n "${TEST_ORG_REPO}" ]; then + cat acceptance/testdata/org.hra.yaml | kubectl apply -f - + else + echo 'Skipped deploying organizational hra. Set TEST_ORG_REPO to "yourorg/yourrepo" to deploy.' + fi +else + echo 'Skipped deploying organizational runnerdeployment. Set TEST_ORG to deploy.' +fi diff --git a/acceptance/kind.yaml b/acceptance/kind.yaml new file mode 100644 index 0000000000..0180585567 --- /dev/null +++ b/acceptance/kind.yaml @@ -0,0 +1,10 @@ +apiVersion: kind.x-k8s.io/v1alpha4 +kind: Cluster +nodes: +- role: control-plane + extraPortMappings: + - containerPort: 31000 + hostPort: 31000 + listenAddress: "0.0.0.0" + protocol: tcp +#- role: worker diff --git a/acceptance/testdata/hra.yaml b/acceptance/testdata/hra.yaml new file mode 100644 index 0000000000..514d8b7474 --- /dev/null +++ b/acceptance/testdata/hra.yaml @@ -0,0 +1,25 @@ +apiVersion: actions.summerwind.dev/v1alpha1 +kind: HorizontalRunnerAutoscaler +metadata: + name: actions-runner-aos-autoscaler +spec: + scaleTargetRef: + name: example-runnerdeploy + scaleUpTriggers: + - githubEvent: + checkRun: + types: ["created"] + status: "queued" + amount: 1 + duration: "1m" + minReplicas: 0 + maxReplicas: 5 + metrics: + - type: PercentageRunnersBusy + scaleUpThreshold: '0.75' + scaleDownThreshold: '0.3' + scaleUpFactor: '2' + scaleDownFactor: '0.5' + - type: TotalNumberOfQueuedAndInProgressWorkflowRuns + repositoryNames: + - ${TEST_REPO} diff --git a/acceptance/testdata/org.hra.yaml b/acceptance/testdata/org.hra.yaml new file mode 100644 index 0000000000..8425562d48 --- /dev/null +++ b/acceptance/testdata/org.hra.yaml @@ -0,0 +1,25 @@ +apiVersion: actions.summerwind.dev/v1alpha1 +kind: HorizontalRunnerAutoscaler +metadata: + name: org +spec: + scaleTargetRef: + name: org-runnerdeploy + scaleUpTriggers: + - githubEvent: + checkRun: + types: ["created"] + status: "queued" + amount: 1 + duration: "1m" + minReplicas: 0 + maxReplicas: 5 + metrics: + - type: PercentageRunnersBusy + scaleUpThreshold: '0.75' + scaleDownThreshold: '0.3' + scaleUpFactor: '2' + scaleDownFactor: '0.5' + - type: TotalNumberOfQueuedAndInProgressWorkflowRuns + repositoryNames: + - ${TEST_ORG_REPO} diff --git a/acceptance/testdata/org.runnerdeploy.yaml b/acceptance/testdata/org.runnerdeploy.yaml new file mode 100644 index 0000000000..6303c95c46 --- /dev/null +++ b/acceptance/testdata/org.runnerdeploy.yaml @@ -0,0 +1,37 @@ +apiVersion: actions.summerwind.dev/v1alpha1 +kind: RunnerDeployment +metadata: + name: org-runnerdeploy +spec: +# replicas: 1 + template: + spec: + organization: ${TEST_ORG} + + # + # Custom runner image + # + image: ${RUNNER_NAME}:${RUNNER_TAG} + imagePullPolicy: IfNotPresent + + # + # dockerd within runner container + # + ## Replace `mumoshu/actions-runner-dind:dev` with your dind image + #dockerdWithinRunnerContainer: true + #image: mumoshu/actions-runner-dind:dev + + # + # Set the MTU used by dockerd-managed network interfaces (including docker-build-ubuntu) + # + #dockerMTU: 1450 + + #Runner group + # labels: + # - "mylabel 1" + # - "mylabel 2" + + # + # Non-standard working directory + # + # workDir: "/" diff --git a/acceptance/values.yaml b/acceptance/values.yaml new file mode 100644 index 0000000000..325944a9f7 --- /dev/null +++ b/acceptance/values.yaml @@ -0,0 +1,20 @@ +# Set actions-runner-controller settings for testing +githubAPICacheDuration: 10s +githubWebhookServer: + enabled: true + labels: {} + replicaCount: 1 + syncPeriod: 10m + secret: + create: true + name: "github-webhook-server" + ### GitHub Webhook Configuration + #github_webhook_secret_token: "" + service: + type: NodePort + ports: + - port: 80 + targetPort: http + protocol: TCP + name: http + nodePort: 31000