From daf69e1ad779c786bff15870137eae9fa7b12603 Mon Sep 17 00:00:00 2001 From: Daan Selen Date: Wed, 23 Jul 2025 12:26:46 +0200 Subject: [PATCH] Rebase all into one commit. I should have used a branch Trying out a readiness check Added init-container for dind Use a more graceful netcat command Slimmed some things down Added docker cli and use that for its readiness check fix: unittest Added parameter for deploying multiple runners Fix unittest job remove reference nc command remove reference in unittest again Trying to fix unittests Passing unit tests readme update readme making using pnpm --- README.md | 1 + templates/_helpers.tpl | 16 ---------------- templates/job.yaml | 5 +++-- templates/statefulset.yaml | 17 +++++++++++++++-- unittests/helm/job.yaml | 7 ++++--- unittests/helm/statefulset.yaml | 23 +++++++++++++---------- values.yaml | 2 ++ 7 files changed, 38 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index d9487fa..b7630d2 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ If `.Values.image.rootless: true`, then the following will occur. In case you us | `enabled` | Create an act runner StatefulSet. | `false` | | `init.image.repository` | The image used for the init containers | `busybox` | | `init.image.tag` | The image tag used for the init containers | `1.37.0` | +| `statefulset.replicas` | the amount of (replica) runners deployed | `1` | | `statefulset.annotations` | Act runner annotations | `{}` | | `statefulset.labels` | Act runner labels | `{}` | | `statefulset.resources` | Act runner resources | `{}` | diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 2796136..ce39bee 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -113,19 +113,3 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{/* Parse the http url to hostname + port separated by space for the nc command */}} -{{- define "gitea.actions.nc" -}} -{{- $url := include "gitea.actions.local_root_url" . | urlParse -}} -{{- $host := get $url "host" -}} -{{- $scheme := get $url "scheme" -}} -{{- $port := "80" -}} -{{- if contains ":" $host -}} - {{- $hostAndPort := regexSplit ":" $host 2 -}} - {{- $host = index $hostAndPort 0 -}} - {{- $port = index $hostAndPort 1 -}} -{{- else if eq $scheme "https" -}} - {{- $port = "443" -}} -{{- else if eq $scheme "http" -}} - {{- $port = "80" -}} -{{- end -}} -{{- printf "%s %s" $host $port -}} -{{- end -}} diff --git a/templates/job.yaml b/templates/job.yaml index 92afbc4..7814e64 100644 --- a/templates/job.yaml +++ b/templates/job.yaml @@ -36,8 +36,9 @@ spec: - sh - -c - | - while ! nc -z {{ include "gitea.actions.nc" . }}; do - sleep 5 + echo 'Waiting for gitea...' + while ! wget -qO- {{ include "gitea.actions.local_root_url" . }} > /dev/null; do + sleep 2 done containers: - name: actions-token-create diff --git a/templates/statefulset.yaml b/templates/statefulset.yaml index d65db12..12cc5be 100644 --- a/templates/statefulset.yaml +++ b/templates/statefulset.yaml @@ -16,6 +16,7 @@ metadata: name: {{ include "gitea.actions.fullname" . }}-act-runner namespace: {{ .Values.namespace | default .Release.Namespace }} spec: + replicas: {{ .Values.statefulset.replicas | default 1 }} selector: matchLabels: {{- include "gitea.actions.selectorLabels.actRunner" . | nindent 6 }} @@ -36,14 +37,26 @@ spec: - sh - -c - | - while ! nc -z {{ include "gitea.actions.nc" . }}; do - sleep 5 + echo 'Waiting for gitea...' + while ! wget -qO- {{ include "gitea.actions.local_root_url" . }} > /dev/null; do + sleep 2 done containers: - name: act-runner image: "{{ .Values.statefulset.actRunner.repository }}:{{ .Values.statefulset.actRunner.tag }}" imagePullPolicy: {{ .Values.statefulset.actRunner.pullPolicy }} workingDir: /data + command: + - sh + - -c + - | + apk add --no-cache docker-cli + echo "Waiting for Docker daemon..." + until docker info > /dev/null 2>&1; do + sleep 2 + done + echo "Docker is ready, starting act-runner..." + exec run.sh env: - name: DOCKER_HOST value: tcp://127.0.0.1:2376 diff --git a/unittests/helm/job.yaml b/unittests/helm/job.yaml index 476053b..bb2e0c5 100644 --- a/unittests/helm/job.yaml +++ b/unittests/helm/job.yaml @@ -60,7 +60,7 @@ tests: asserts: - hasDocuments: count: 0 - - it: renders a Job with correct nc command + - it: renders a Job with correct wget wait command template: templates/job.yaml set: enabled: true @@ -83,6 +83,7 @@ tests: - equal: path: spec.template.spec.initContainers[0].command[2] value: | - while ! nc -z git.example.com 8443; do - sleep 5 + echo 'Waiting for gitea...' + while ! wget -qO- https://git.example.com:8443 > /dev/null; do + sleep 2 done diff --git a/unittests/helm/statefulset.yaml b/unittests/helm/statefulset.yaml index 47ea4a3..915859b 100644 --- a/unittests/helm/statefulset.yaml +++ b/unittests/helm/statefulset.yaml @@ -73,7 +73,7 @@ tests: - it: renders a StatefulSet http (with correct GITEA_INSTANCE_URL env from giteaRootURL) template: templates/statefulset.yaml set: - giteaRootURL: "http://git.example.com" + giteaRootURL: "https://git.example.com" enabled: true existingSecret: "my-secret" existingSecretKey: "my-secret-key" @@ -88,12 +88,13 @@ tests: path: spec.template.spec.containers[0].env[4] value: name: GITEA_INSTANCE_URL - value: "http://git.example.com" + value: "https://git.example.com" - equal: path: spec.template.spec.initContainers[0].command[2] value: | - while ! nc -z git.example.com 80; do - sleep 5 + echo 'Waiting for gitea...' + while ! wget -qO- https://git.example.com > /dev/null; do + sleep 2 done - it: renders a StatefulSet https (with correct GITEA_INSTANCE_URL env from giteaRootURL) template: templates/statefulset.yaml @@ -117,13 +118,14 @@ tests: - equal: path: spec.template.spec.initContainers[0].command[2] value: | - while ! nc -z git.example.com 443; do - sleep 5 + echo 'Waiting for gitea...' + while ! wget -qO- https://git.example.com > /dev/null; do + sleep 2 done - it: renders a StatefulSet https (with correct GITEA_INSTANCE_URL env from giteaRootURL) template: templates/statefulset.yaml set: - giteaRootURL: "https://git.example.com:8443" + giteaRootURL: "https://git.example.com" enabled: true existingSecret: "my-secret" existingSecretKey: "my-secret-key" @@ -138,12 +140,13 @@ tests: path: spec.template.spec.containers[0].env[4] value: name: GITEA_INSTANCE_URL - value: "https://git.example.com:8443" + value: "https://git.example.com" - equal: path: spec.template.spec.initContainers[0].command[2] value: | - while ! nc -z git.example.com 8443; do - sleep 5 + echo 'Waiting for gitea...' + while ! wget -qO- https://git.example.com > /dev/null; do + sleep 2 done - it: allows adding custom environment variables to the docker-in-docker container template: templates/statefulset.yaml diff --git a/values.yaml b/values.yaml index ab97400..32bbb82 100644 --- a/values.yaml +++ b/values.yaml @@ -5,6 +5,7 @@ ## @param enabled Create an act runner StatefulSet. ## @param init.image.repository The image used for the init containers ## @param init.image.tag The image tag used for the init containers +## @param statefulset.replicas the amount of (replica) runners deployed ## @param statefulset.annotations Act runner annotations ## @param statefulset.labels Act runner labels ## @param statefulset.resources Act runner resources @@ -39,6 +40,7 @@ ## @param giteaRootURL URL the act_runner registers and connect with enabled: false statefulset: + replicas: 1 annotations: {} labels: {} resources: {}