From 600b45b59854044d7fad4d32d9e4589c048e2bd4 Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Fri, 16 Jan 2026 16:12:39 +0100 Subject: [PATCH] better coverage but still more to do --- .../templates/_helpers.tpl | 36 ++++++------------- .../templates/autoscalingrunnserset.yaml | 5 ++- .../autoscaling_runner_set_labels_test.yaml | 6 ++-- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/charts/gha-runner-scale-set-dev/templates/_helpers.tpl b/charts/gha-runner-scale-set-dev/templates/_helpers.tpl index 25366f52..829bfbd6 100644 --- a/charts/gha-runner-scale-set-dev/templates/_helpers.tpl +++ b/charts/gha-runner-scale-set-dev/templates/_helpers.tpl @@ -29,8 +29,8 @@ Create the labels for the autoscaling runner set. {{- define "autoscaling-runner-set.labels" -}} {{- $resourceLabels := dict "app.kubernetes.io/component" "autoscaling-runner-set" -}} {{- $commonLabels := include "gha-common-labels" . | fromYaml -}} -{{- $userLabels := include "gha-process-labels" (.Values.resource.autoscalingRunnerSet.metadata.labels | default (dict)) | fromYaml -}} -{{- $global := include "gha-process-labels" (.Values.resource.all.metadata.labels | default (dict)) | fromYaml -}} +{{- $userLabels := include "apply-non-reserved-gha-labels-and-annotations" (.Values.resource.autoscalingRunnerSet.metadata.labels | default (dict)) | fromYaml -}} +{{- $global := include "apply-non-reserved-gha-labels-and-annotations" (.Values.resource.all.metadata.labels | default (dict)) | fromYaml -}} {{- toYaml (mergeOverwrite $global $userLabels $resourceLabels $commonLabels) }} {{- end }} @@ -52,33 +52,17 @@ actions.github.com/scale-set-namespace: {{ include "autoscaling-runner-set.names {{/* Takes a map of user labels and removes the ones with "actions.github.com/" prefix */}} -{{- define "gha-process-labels" -}} +{{- define "apply-non-reserved-gha-labels-and-annotations" -}} {{- $userLabels := . -}} {{- $processed := dict -}} {{- range $key, $value := $userLabels -}} - {{- if not (hasPrefix $key "actions.github.com/") -}} + {{- if not (hasPrefix "actions.github.com/" $key) -}} {{- $_ := set $processed $key $value -}} {{- end -}} {{- end -}} -{{- $processed | toYaml -}} +{{- if not (empty $processed) -}} + {{- $processed | toYaml }} {{- end }} - -{{/* -Takes a map of user annotations and removes reserved ones. - -Reserved annotations are managed by ARC/controllers and should not be set by users: -- actions.github.com/cleanup-* -- actions.github.com/values-hash -*/}} -{{- define "gha-process-annotations" -}} -{{- $userAnnotations := . -}} -{{- $processed := dict -}} -{{- range $key, $value := $userAnnotations -}} - {{- if not (or (hasPrefix "actions.github.com/cleanup-" $key) (eq $key "actions.github.com/values-hash")) -}} - {{- $_ := set $processed $key $value -}} - {{- end -}} -{{- end -}} -{{- $processed | toYaml -}} {{- end }} {{/* @@ -90,11 +74,11 @@ Order of precedence: Reserved annotations are excluded from both levels. */}} {{- define "autoscaling-runner-set.annotations" -}} -{{- $global := include "gha-process-annotations" (.Values.resource.all.metadata.annotations | default (dict)) | fromYaml -}} -{{- $resource := include "gha-process-annotations" (.Values.resource.autoscalingRunnerSet.metadata.annotations | default (dict)) | fromYaml -}} +{{- $global := (include "apply-non-reserved-gha-labels-and-annotations" (.Values.resource.all.metadata.annotations | default (dict))) | fromYaml -}} +{{- $resource := (include "apply-non-reserved-gha-labels-and-annotations" (.Values.resource.autoscalingRunnerSet.metadata.annotations | default (dict))) | fromYaml -}} {{- $annotations := mergeOverwrite $global $resource -}} -{{- range $k, $v := $annotations }} -{{ $k }}: {{ $v | quote }} +{{- if not (empty $annotations) -}} +{{- toYaml $annotations }} {{- end }} {{- end }} diff --git a/charts/gha-runner-scale-set-dev/templates/autoscalingrunnserset.yaml b/charts/gha-runner-scale-set-dev/templates/autoscalingrunnserset.yaml index 06b9249f..85733bbe 100644 --- a/charts/gha-runner-scale-set-dev/templates/autoscalingrunnserset.yaml +++ b/charts/gha-runner-scale-set-dev/templates/autoscalingrunnserset.yaml @@ -96,4 +96,7 @@ spec: template: spec: - containers: \ No newline at end of file + containers: + - name: runner + image: {{ .Values.runner.container.image | default "ghcr.io/actions/actions-runner:latest" | quote }} + command: {{ toJson (default (list "/home/runner/run.sh") .Values.runner.container.command) }} \ No newline at end of file diff --git a/charts/gha-runner-scale-set-dev/tests/autoscaling_runner_set_labels_test.yaml b/charts/gha-runner-scale-set-dev/tests/autoscaling_runner_set_labels_test.yaml index 15814000..71cbabf5 100644 --- a/charts/gha-runner-scale-set-dev/tests/autoscaling_runner_set_labels_test.yaml +++ b/charts/gha-runner-scale-set-dev/tests/autoscaling_runner_set_labels_test.yaml @@ -260,9 +260,8 @@ tests: - equal: path: metadata.labels["team"] value: "backend" - - equal: + - notExists: path: metadata.labels["actions.github.com/custom-label"] - value: "user-value" - equal: path: metadata.labels["actions.github.com/scale-set-name"] value: "test-name" @@ -287,9 +286,8 @@ tests: - equal: path: metadata.labels["owner"] value: "devops" - - equal: + - notExists: path: metadata.labels["actions.github.com/global-custom"] - value: "global-value" - equal: path: metadata.labels["actions.github.com/scale-set-name"] value: "test-name" \ No newline at end of file