Add support for operator environment variables#215
Conversation
Allow overriding environment variables on the operator deployment, useful for setting RELATED_IMAGE_* vars to test with custom-built component images. Supports both non-OLM (direct injection into the manager container) and OLM (via Subscription spec.config.env) paths. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughA new ChangesOperator Env Var Injection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 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 docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabitai review |
- Rename operatorEnvVarsToSortedList to envVarsToSortedList - Simplify ParseOperatorEnvVars to ParseOperatorEnvVar taking a single KEY=VALUE string (no comma splitting or space trimming) - Use Dimf instead of Dim(fmt.Sprintf(...)) - Switch tests to use testify require/assert Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
internal/deployer/operator.go (1)
541-545: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winSurface when env injection is skipped due to missing
managercontainer.When env vars are configured but no
name: managercontainer exists, injection silently no-ops. Emit a signal (bool/error + log) so misconfiguration is visible.🔧 Suggested fix
- if containers, ok := podSpec["containers"].([]interface{}); ok { - d.injectEnvVarsIntoManagerContainer(containers) + if containers, ok := podSpec["containers"].([]interface{}); ok { + if !d.injectEnvVarsIntoManagerContainer(containers) { + d.logger.Infof("Custom operator env vars configured, but container %q was not found; skipping injection", managerContainerName) + } } } } } @@ -func (d *Deployer) injectEnvVarsIntoManagerContainer(containers []interface{}) { +func (d *Deployer) injectEnvVarsIntoManagerContainer(containers []interface{}) bool { for _, c := range containers { container, ok := c.(map[string]interface{}) if !ok { continue } @@ container["env"] = envList - return + return true } + return false }Also applies to: 568-600
🤖 Prompt for 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. In `@internal/deployer/operator.go` around lines 541 - 545, The injectEnvVarsIntoManagerContainer method silently skips injection if the manager container is not found, which masks misconfiguration. Modify the injectEnvVarsIntoManagerContainer method to return a bool or error indicating whether the manager container was successfully found and updated. In the code block where injectEnvVarsIntoManagerContainer is called (around line 541), check the return value and log a warning if the manager container was not found, ensuring that misconfigured setups become visible rather than silently no-oping. Apply the same fix to all other locations where injectEnvVarsIntoManagerContainer is called as mentioned in the comment range 568-600.
🤖 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 `@cmd/deploy_test.go`:
- Around line 156-162: The test case "operator-env comma separated" expects
comma-separated environment variables to be parsed into separate map entries,
but the ParseOperatorEnvVar function only splits on the first equals sign and
does not implement comma-splitting logic. Either remove this test case entirely
if comma-separated values are not a supported feature, or implement
comma-splitting logic in the apply function that handles the --operator-env flag
to split the value on commas before individually parsing each key-value pair
into the EnvVars map.
In `@internal/deployer/operator_env_test.go`:
- Around line 74-75: The TestEnvVarsToSortedList function has an extra blank
line before it, causing a gofmt formatting violation. Remove the extra blank
line that appears immediately before the TestEnvVarsToSortedList function
declaration to comply with Go formatting standards and resolve the CI formatting
drift.
In `@internal/deployer/operator.go`:
- Around line 327-332: The logging of operator environment variables in
operator.go is exposing raw values which can leak sensitive secrets or tokens
into deploy logs. In the loop that iterates over
envVarsToSortedList(d.config.Operator.EnvVars), modify the logger.Dimf call to
only log the environment variable names by removing the value part from the
format string and arguments. Apply the identical fix to operator_olm.go at lines
36-41 where the same pattern exists.
---
Nitpick comments:
In `@internal/deployer/operator.go`:
- Around line 541-545: The injectEnvVarsIntoManagerContainer method silently
skips injection if the manager container is not found, which masks
misconfiguration. Modify the injectEnvVarsIntoManagerContainer method to return
a bool or error indicating whether the manager container was successfully found
and updated. In the code block where injectEnvVarsIntoManagerContainer is called
(around line 541), check the return value and log a warning if the manager
container was not found, ensuring that misconfigured setups become visible
rather than silently no-oping. Apply the same fix to all other locations where
injectEnvVarsIntoManagerContainer is called as mentioned in the comment range
568-600.
🪄 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: Path: .coderabbit.yml
Review profile: CHILL
Plan: Enterprise
Run ID: af74d7fd-907a-4995-a9bb-e8be86dbfb67
📒 Files selected for processing (7)
cmd/deploy.gocmd/deploy_test.gointernal/deployer/config.gointernal/deployer/operator.gointernal/deployer/operator_env.gointernal/deployer/operator_env_test.gointernal/deployer/operator_olm.go
Make env var injection fail loudly instead of silently succeeding when the manager container is not found in the deployment spec. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
porridge
left a comment
There was a problem hiding this comment.
Feedback addressed, I also added a change to complain loudly if injection was requested and did not happen (in case the manager deployment structure evolved behind our back).
PTAL.
|
PTAL @mclasmeier |
Summary
--operator-env KEY=VALUECLI flag for setting env vars on the operator deploymentoperator.envVarsmapmanagercontainer of the CSV-derived deploymentspec.config.envon the Subscription so OLM propagates to the deploymentRELATED_IMAGE_*variables to test with custom-built component images, in particular to support custom images in stackrox "infra" service.Usage
Test plan
ParseOperatorEnvVar— valid pairs, values with=/commas/spaces, missing=, empty keyenvVarsToSortedList— sort orderoperator.envVarsmapgo build ./...,go test ./...,go vet ./...all pass🤖 Generated with Claude Code
Summary by CodeRabbit
--operator-env(singleKEY=VALUE, comma-separated lists, and repeated flags).operator.envVars.--operator-envexpressions.