Repository navigation
[feat] Add codeExecutor.env and codeExecutor.environmentVariables #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cameronattard
wants to merge
1
commit into
tryretool:main
Choose a base branch
from
cameronattard:feat/code-executor-env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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")) | ||
|
|
||
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.secretKeyRefentry 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!
There was a problem hiding this comment.
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_fullasserts the fullvalueFrom.secretKeyRefentry on the code executor and that it stays off the backend. It fails if the template drops the list.