From 49a8f77e2573e87eb22e2770281eb249bc62b886 Mon Sep 17 00:00:00 2001 From: jojosenthusiast Date: Sun, 28 Jun 2026 18:10:13 -0600 Subject: [PATCH] fix(executor): render tolerations as json --- .../k8s/templates/executor.ConfigMap.yaml | 2 +- .../k8s/tests/executor_test.yaml | 40 +++++++++++++++++++ scripts/ci/helm-unittest.sh | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml index 3c233f387..69ed7734f 100644 --- a/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml +++ b/charts/sourcegraph-executor/k8s/templates/executor.ConfigMap.yaml @@ -22,7 +22,7 @@ data: EXECUTOR_KUBERNETES_NODE_NAME: "{{ .Values.executor.kubernetesJob.node.name }}" EXECUTOR_KUBERNETES_NODE_SELECTOR: "{{ .Values.executor.kubernetesJob.node.selector }}" - EXECUTOR_KUBERNETES_NODE_TOLERATIONS: "{{ .Values.executor.kubernetesJob.node.tolerations }}" + EXECUTOR_KUBERNETES_NODE_TOLERATIONS: {{ if kindIs "string" .Values.executor.kubernetesJob.node.tolerations }}{{ .Values.executor.kubernetesJob.node.tolerations | quote }}{{ else }}{{ .Values.executor.kubernetesJob.node.tolerations | toJson | quote }}{{ end }} EXECUTOR_KUBERNETES_NODE_REQUIRED_AFFINITY_MATCH_EXPRESSIONS: "{{ .Values.executor.kubernetesJob.node.requiredAffinityMatchExpressions }}" EXECUTOR_KUBERNETES_NODE_REQUIRED_AFFINITY_MATCH_FIELDS: "{{ .Values.executor.kubernetesJob.node.requiredAffinityMatchFields }}" diff --git a/charts/sourcegraph-executor/k8s/tests/executor_test.yaml b/charts/sourcegraph-executor/k8s/tests/executor_test.yaml index 84c0aceb0..e5f40538e 100644 --- a/charts/sourcegraph-executor/k8s/tests/executor_test.yaml +++ b/charts/sourcegraph-executor/k8s/tests/executor_test.yaml @@ -131,3 +131,43 @@ tests: path: spec.template.spec.securityContext.runAsUser - isNull: path: spec.template.spec.securityContext.runAsGroup + + - it: should JSON-encode kubernetesJob.node.tolerations when given a YAML list (issue #349) + template: executor.ConfigMap.yaml + set: + executor: + queueName: "test" + kubernetesJob: + node: + tolerations: + - key: foo + operator: Equal + value: bar + effect: NoSchedule + asserts: + - equal: + path: data.EXECUTOR_KUBERNETES_NODE_TOLERATIONS + value: '[{"effect":"NoSchedule","key":"foo","operator":"Equal","value":"bar"}]' + + - it: should pass through kubernetesJob.node.tolerations when given a pre-encoded JSON string + template: executor.ConfigMap.yaml + set: + executor: + queueName: "test" + kubernetesJob: + node: + tolerations: '[{"key":"foo","operator":"Equal","value":"bar","effect":"NoSchedule"}]' + asserts: + - equal: + path: data.EXECUTOR_KUBERNETES_NODE_TOLERATIONS + value: '[{"key":"foo","operator":"Equal","value":"bar","effect":"NoSchedule"}]' + + - it: should render default kubernetesJob.node.tolerations as empty string + template: executor.ConfigMap.yaml + set: + executor: + queueName: "test" + asserts: + - equal: + path: data.EXECUTOR_KUBERNETES_NODE_TOLERATIONS + value: "" diff --git a/scripts/ci/helm-unittest.sh b/scripts/ci/helm-unittest.sh index 3ec626947..0a067f14d 100755 --- a/scripts/ci/helm-unittest.sh +++ b/scripts/ci/helm-unittest.sh @@ -11,3 +11,4 @@ helm plugin install https://github.com/helm-unittest/helm-unittest --version "$H ### Run the helm tests helm unittest -q charts/sourcegraph +helm unittest -q charts/sourcegraph-executor/k8s