feat: support activation job namespace override via env var#1546
Conversation
📝 WalkthroughWalkthroughThe PR adds namespace override support to the Kubernetes engine by reading the ChangesNamespace Override with Environment Variable
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Read EDA_ACTIVATION_JOB_NAMESPACE environment variable in _set_namespace() as an override before falling back to the ServiceAccount token namespace file. This allows the eda-server-operator to direct activation job pods into a separate Kubernetes namespace for security isolation, resource quotas, and NetworkPolicy boundaries. Changes: - _set_namespace() checks EDA_ACTIVATION_JOB_NAMESPACE first - Unit tests for override, fallback, whitespace handling, and error case Companion operator PR: ansible/eda-server-operator#345 Signed-off-by: Alexey Masolov <amasolov@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>
385aa84 to
475abf8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #1546 +/- ##
=======================================
Coverage 92.01% 92.02%
=======================================
Files 241 241
Lines 10972 10978 +6
=======================================
+ Hits 10096 10102 +6
Misses 876 876
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@amasolov Should we follow the same pattern as we did with service accounts, where we had an approved list of SA's that the user could use when starting an Activation. Should we have an approved list of Namespaces so we dont just use 1 Namespace from env var. Could there be a mismatch between which SA's would work with which Namespaces? |
@mkanoor Extending this to an approved list of namespaces (and mapping which SAs are valid for which namespaces) makes sense as a follow-up when multi-tenant or per-team isolation is needed. My customer wants a bare minimum: a separate namespace and this is what I'm aiming for here. I can open another issue for the full multi-tenant setup. Does that approach work for you? |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit/test_activation_job_namespace.py`:
- Around line 89-96: The test test_set_namespace_no_env_no_file_raises is
nondeterministic because it relies on the real filesystem; wrap the test body
with a mock that forces open() to fail by patching builtins.open to raise
FileNotFoundError (e.g. using mock.patch("builtins.open",
side_effect=FileNotFoundError)) while keeping the existing mock.patch.dict for
os.environ, then assert Engine(...) raises ContainerEngineInitError as before so
the test no longer depends on any existing namespace file.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: aab35a14-eb92-4f78-ac56-ebaa57e961f5
📒 Files selected for processing (2)
src/aap_eda/services/activation/engine/kubernetes.pytests/unit/test_activation_job_namespace.py
|
Merge latest main to resolve conflicts with merged PR ansible#1520 (pod metadata) and PR ansible#1546 (namespace override). Retain all resource limits additions unique to this branch. Signed-off-by: Alexey Masolov <amasolov@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>



Summary
EDA_ACTIVATION_JOB_NAMESPACEenvironment variable support to_set_namespace()in the Kubernetes engine, allowing activation job pods to be directed into a separate namespace.What changed
_set_namespace()readsEDA_ACTIVATION_JOB_NAMESPACEfirst, falling back to the ServiceAccount token namespace file when the variable is unset or empty.Why
Running activation job pods in a dedicated namespace provides security isolation (user-supplied rulebooks and decision environments are separated from the EDA control plane), independent ResourceQuota/LimitRange policies, and NetworkPolicy boundaries. The companion operator PR (ansible/eda-server-operator#345) injects this env var and manages cross-namespace RBAC.
How to test
Breaking changes / dependencies
None. When the env var is unset (default), behaviour is unchanged.
Companion PR: ansible/eda-server-operator#345
Related: ansible/eda-server-operator#344
Made with Cursor
Summary by CodeRabbit
Release Notes
New Features
Tests