Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions .github/test_code_executor_env.py
Original file line number Diff line number Diff line change
@@ -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"))
Comment on lines +46 to +50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Secret-backed entries go untested

The new list test checks only the variable's name. It never supplies or checks valueFrom, although secret-backed entries are part of this feature. The CI fixture includes one, but its schema check would still pass if the template dropped the entry entirely.

Add a render assertion for the full valueFrom.secretKeyRef entry and confirm it stays out of the backend. This is non-blocking test coverage feedback.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 5c8665f: test_secret_backed_list_entry_renders_in_full asserts the full valueFrom.secretKeyRef entry on the code executor and that it stays off the backend. It fails if the template drops the list.


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()
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion charts/retool/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions charts/retool/ci/test-code-executor-env-option.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions charts/retool/templates/deployment_code_executor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions charts/retool/values.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions values.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.