From bd2fcb14be144584cf378bf33ac9bdb49d9e7250 Mon Sep 17 00:00:00 2001 From: Christopher Homberger Date: Sun, 21 Sep 2025 18:21:34 +0000 Subject: [PATCH] feat: allow inline yaml config instead of string literal (#43) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description of the change Allow to insert the act_runner config as yaml into the chart values. ### Benefits Yaml editor will report yaml errors, instead of the deployed runner. ### Possible drawbacks No limitations, string config works like before. ### Applicable issues N/A ### Additional information Usage like this, just omit the block scalar token ```yaml enabled: true statefulset: actRunner: # See full example here: https://gitea.com/gitea/act_runner/src/branch/main/internal/pkg/config/config.example.yaml config: log: level: debug cache: enabled: false container: valid_volumes: - /var/run/docker.sock options: -v /var/run/docker.sock:/var/run/docker.sock ## Specify an existing token secret ## existingSecret: "runner-token2" existingSecretKey: "token" ## Specify the root URL of the Gitea instance giteaRootURL: "http://192.168.1.2:3000" ``` I do not like the regex test approach, but I didn't come up with a better one. I wish that I can parse the nested yaml in the helm tests. ### ⚠ BREAKING N/A ### Checklist - [x] Helm templating unittests are added (required when changing anything in `templates` folder) - [x] All added template resources MUST render a namespace in metadata Reviewed-on: https://gitea.com/gitea/helm-actions/pulls/43 Reviewed-by: DaanSelen Co-authored-by: Christopher Homberger Co-committed-by: Christopher Homberger --- templates/config-act-runner.yaml | 4 ++++ unittests/helm/config-act-runner.yaml | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/templates/config-act-runner.yaml b/templates/config-act-runner.yaml index e82664a..8e8874b 100644 --- a/templates/config-act-runner.yaml +++ b/templates/config-act-runner.yaml @@ -10,6 +10,10 @@ metadata: data: config.yaml: | {{- with .Values.statefulset.actRunner.config -}} + {{- if kindIs "string" . -}} {{ . | nindent 4}} + {{- else -}} + {{ toYaml . | nindent 4}} + {{- end -}} {{- end -}} {{- end }} diff --git a/unittests/helm/config-act-runner.yaml b/unittests/helm/config-act-runner.yaml index dc7a0e8..43e9524 100644 --- a/unittests/helm/config-act-runner.yaml +++ b/unittests/helm/config-act-runner.yaml @@ -42,3 +42,27 @@ tests: runner: labels: - "ubuntu-latest" + - it: renders a ConfigMap with inline yaml + template: templates/config-act-runner.yaml + set: + enabled: true + statefulset: + actRunner: + config: + container: + valid_volumes: + - /var/run/docker.sock + options: -v /var/run/docker.sock:/var/run/docker.sock + asserts: + - hasDocuments: + count: 1 + - containsDocument: + kind: ConfigMap + apiVersion: v1 + name: gitea-unittests-actions-act-runner-config + - matchRegex: + path: data["config.yaml"] + pattern: '(?m)^\s*options:\s*-v /var/run/docker.sock:/var/run/docker.sock\s*$' + - matchRegex: + path: data["config.yaml"] + pattern: '(?m)^\s*valid_volumes:\s*\n\s*-\s*/var/run/docker.sock\s*$'