diff --git a/.github/test_code_executor_env.py b/.github/test_code_executor_env.py new file mode 100644 index 00000000..5c62d041 --- /dev/null +++ b/.github/test_code_executor_env.py @@ -0,0 +1,78 @@ +"""Check codeExecutor.env / codeExecutor.environmentVariables. + +They let an install set environment that only the code executor reads without +putting it on every Retool pod via the top-level env. +""" + +import subprocess +import unittest +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[1] + + +def render(*settings): + command = [ + "helm", "template", "ce", "charts/retool", + "--values", "charts/retool/ci/test-install-values.yaml", + "--set", "workflows.enabled=true", + ] + for setting in settings: + command.extend(("--set", setting)) + return subprocess.check_output(command, cwd=ROOT, text=True) + + +def env_names(output, source): + for document in output.split("\n---\n"): + if f"# Source: retool/templates/{source}" in document[:200] and "\nkind: Deployment\n" in document: + return [line.split("- name:", 1)[1].strip().strip('"') + for line in document.splitlines() if line.strip().startswith("- name:")] + raise AssertionError(f"no Deployment rendered from {source}") + + +def deployment(output, source): + (document,) = [d for d in output.split("\n---\n") + if f"# Source: retool/templates/{source}\n" in d and "\nkind: Deployment\n" in d] + return document + + +class CodeExecutorEnvTest(unittest.TestCase): + def test_map_env_reaches_only_the_code_executor(self): + out = render("codeExecutor.env.CODE_EXECUTOR_ONLY_SETTING=true") + self.assertIn("CODE_EXECUTOR_ONLY_SETTING", env_names(out, "deployment_code_executor.yaml")) + self.assertNotIn("CODE_EXECUTOR_ONLY_SETTING", env_names(out, "deployment_backend.yaml")) + + def test_list_env_reaches_the_code_executor(self): + out = render("codeExecutor.environmentVariables[0].name=CE_ONLY", + "codeExecutor.environmentVariables[0].value=1") + self.assertIn("CE_ONLY", env_names(out, "deployment_code_executor.yaml")) + self.assertNotIn("CE_ONLY", env_names(out, "deployment_backend.yaml")) + + def test_secret_backed_list_entry_renders_in_full(self): + out = render("codeExecutor.environmentVariables[0].name=CE_SECRET", + "codeExecutor.environmentVariables[0].valueFrom.secretKeyRef.name=ce-secrets", + "codeExecutor.environmentVariables[0].valueFrom.secretKeyRef.key=token") + entry = ("- name: CE_SECRET\n" + " valueFrom:\n" + " secretKeyRef:\n" + " key: token\n" + " name: ce-secrets\n") + self.assertIn(entry, deployment(out, "deployment_code_executor.yaml")) + self.assertNotIn("CE_SECRET", deployment(out, "deployment_backend.yaml")) + + def test_code_executor_value_comes_after_the_shared_one(self): + out = render("env.SHARED=global", "codeExecutor.env.SHARED=local") + names = env_names(out, "deployment_code_executor.yaml") + self.assertEqual(names.count("SHARED"), 2) + for document in out.split("\n---\n"): + if "deployment_code_executor.yaml" in document[:200] and "\nkind: Deployment\n" in document: + self.assertLess(document.index('"global"'), document.index('"local"')) + + def test_defaults_add_nothing(self): + self.assertEqual(env_names(render(), "deployment_code_executor.yaml"), + env_names(render("codeExecutor.env=null"), "deployment_code_executor.yaml")) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 823a66de..12410ea7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -100,6 +100,8 @@ jobs: run: python3 .github/test_isolated_pool_scheduling.py - name: Verify code-executor enablement run: python3 .github/test_code_executor.py + - name: Verify code-executor-only environment + run: python3 .github/test_code_executor_env.py - name: Verify values.schema.json accepts and rejects the right values run: python3 .github/test_values_schema.py - name: Verify telemetry ClusterRole names are unique per namespace diff --git a/charts/retool/Chart.yaml b/charts/retool/Chart.yaml index 224769fa..af622cf9 100644 --- a/charts/retool/Chart.yaml +++ b/charts/retool/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: retool description: Deploy self-hosted Retool on Kubernetes. type: application -version: 6.14.2 +version: 6.14.3 maintainers: - name: Retool Engineering email: engineering+helm@retool.com diff --git a/charts/retool/ci/test-code-executor-env-option.yaml b/charts/retool/ci/test-code-executor-env-option.yaml new file mode 100644 index 00000000..3eac3da1 --- /dev/null +++ b/charts/retool/ci/test-code-executor-env-option.yaml @@ -0,0 +1,15 @@ +# Exercises codeExecutor.env and codeExecutor.environmentVariables: settings only +# the code executor reads, rendered after the shared top-level env. Overlaid on +# top of test-install-values.yaml (which enables workflows, and so the code +# executor). +# +# Behavioral assertions for this path live in .github/test_code_executor_env.py. +codeExecutor: + env: + CODE_EXECUTOR_ONLY_SETTING: "true" + environmentVariables: + - name: CODE_EXECUTOR_EXAMPLE_SECRET + valueFrom: + secretKeyRef: + name: code-executor-secrets + key: example diff --git a/charts/retool/templates/deployment_code_executor.yaml b/charts/retool/templates/deployment_code_executor.yaml index a89aace2..abdc9499 100644 --- a/charts/retool/templates/deployment_code_executor.yaml +++ b/charts/retool/templates/deployment_code_executor.yaml @@ -170,6 +170,11 @@ spec: key: {{ .secretKeyRef.key }} {{- end }} {{- with .Values.environmentVariables }} +{{ toYaml . | indent 10 }} + {{- end }} + {{- /* Code-executor-only settings, after the shared ones so they win. */}} + {{- include "retool.env" .Values.codeExecutor.env | nindent 10 }} + {{- with .Values.codeExecutor.environmentVariables }} {{ toYaml . | indent 10 }} {{- end }} ports: diff --git a/charts/retool/values.yaml b/charts/retool/values.yaml index 5b46beee..d5502501 100644 --- a/charts/retool/values.yaml +++ b/charts/retool/values.yaml @@ -1032,6 +1032,15 @@ codeExecutor: # config: { # nodeOptions: --max_old_space_size=1024 # } + + # Code-executor-specific environment, in the same formats as the top-level + # env (map) and environmentVariables (list, including valueFrom entries). The + # code executor still receives the top-level env, environmentSecrets and + # environmentVariables; these are added after them, so a name set in both + # takes this value. Use for settings only the code executor reads, without + # setting them on every Retool pod. + env: {} + environmentVariables: [] volumes: {} volumeMounts: {} diff --git a/values.yaml b/values.yaml index 5b46beee..d5502501 100644 --- a/values.yaml +++ b/values.yaml @@ -1032,6 +1032,15 @@ codeExecutor: # config: { # nodeOptions: --max_old_space_size=1024 # } + + # Code-executor-specific environment, in the same formats as the top-level + # env (map) and environmentVariables (list, including valueFrom entries). The + # code executor still receives the top-level env, environmentSecrets and + # environmentVariables; these are added after them, so a name set in both + # takes this value. Use for settings only the code executor reads, without + # setting them on every Retool pod. + env: {} + environmentVariables: [] volumes: {} volumeMounts: {}