Skip to content

Add env var overrides for controller enable flags#3097

Closed
savec80 wants to merge 1 commit into
DataDog:mainfrom
savec80:feat/env-var-controller-flags
Closed

Add env var overrides for controller enable flags#3097
savec80 wants to merge 1 commit into
DataDog:mainfrom
savec80:feat/env-var-controller-flags

Conversation

@savec80

@savec80 savec80 commented Jun 5, 2026

Copy link
Copy Markdown

Changes

cmd/main.go

  • Added boolFromEnv helper using os.LookupEnv + strconv.ParseBool
  • 12 env var overrides applied before flag.Parse() so CLI flags take precedence
  • Invalid values logged to stderr (logger is not initialized at parse time)

Documentation

Doc Env var documented
docs/installation.md Full reference table with all 12 flags
docs/untaint_controller.md DD_UNTAINT_CONTROLLER_ENABLED
docs/datadog_agent_profiles.md DD_AGENT_PROFILE_CONTROLLER_ENABLED
docs/introspection.md DD_INTROSPECTION_ENABLED
docs/control_plane_monitoring.md DD_INTROSPECTION_ENABLED (OLM alternative to CSV patch)
docs/datadog_dashboard.md DD_DASHBOARD_CONTROLLER_ENABLED
docs/datadog_monitor.md DD_MONITOR_CONTROLLER_ENABLED
docs/datadog_slo.md DD_SLO_CONTROLLER_ENABLED
docs/datadog_generic_resource.md DD_GENERIC_RESOURCE_CONTROLLER_ENABLED

Test plan

  • go build ./cmd/main.go passes
  • go test ./cmd/... passes
  • go vet ./cmd/... clean
  • Set DD_DASHBOARD_CONTROLLER_ENABLED=true on operator pod, verify controller starts
  • Set invalid value (e.g. yes), verify stderr error message
  • Set env var + CLI flag, verify CLI flag wins

OLM deployments cannot override container args — only env vars via
Subscription.spec.config.env. This adds env var fallback for all 12
controller-enable boolean flags, applied before flag.Parse() so that
explicit CLI flags still take precedence (default < env < CLI).

Updated feature docs with OLM env var examples and added a full
flag/env-var reference table to docs/installation.md.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@savec80
savec80 requested a review from a team June 5, 2026 15:11
@savec80
savec80 requested a review from a team as a code owner June 5, 2026 15:11
@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented Jun 5, 2026

Copy link
Copy Markdown

Code Coverage  Pipelines

Fix all issues with BitsAI

🛑 Gate Violations

🎯 1 Code Coverage issue detected

A Patch coverage percentage gate may be blocking this PR.

Patch coverage: 0.00% (threshold: 80.00%)

⚠️ Warnings

🚦 1 Pipeline job failed

pull request linter | build   View in Datadog   GitHub Actions

ℹ️ Info

🎯 Code Coverage (details)
Patch Coverage: 0.00%
Overall Coverage: 43.94% (-0.03%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f899bf9 | Docs | Datadog PR Page | Give us feedback!

@tbavelier

Copy link
Copy Markdown
Member

Hello, thank you for the contribution! I'm closing this PR in favour of #3181 (using your commit to preserve authorship) to allow CI to run, and we'll discuss with the team if we go forward. I made small tweaks to it, but the general idea stands.

Please note commits need to be signed, so while I did use your commit, I might eventually re-write it to have it signed otherwise the PR cannot be merged.

Regards,

@tbavelier tbavelier closed this Jun 19, 2026
tbavelier added a commit that referenced this pull request Jun 25, 2026
>[!NOTE]
> This PR is created by pushing locally the commits from #3097 for the purpose of CI. Original commits are preserved with authorship.

>[!IMPORTANT]
> This PR now goes beyond the original controller-only boolean env-var fallback. It centralizes environment override parsing through a small typed helper so options can share the same precedence model: compiled default < environment variable < CLI flag.
>
> The updated implementation supports boolean, string, integer, and duration env vars, while still applying them before `flag.Parse()` so explicit CLI arguments win. In addition to the controller enable flags, it now covers selected non-EDS startup options such as metrics binding, secure metrics, profiling, pprof, leader election, Cilium support, maximum goroutines, controller revisions, and the untaint controller's CSI readiness gate.
>
> EDS flags, log flags, secret backend flags, and `--version` remain CLI-only. Tests were added for env-over-default behavior, CLI-over-env precedence, and invalid env values preserving defaults.

   ### `cmd/main.go`
   - Added `boolFromEnv` helper using `os.LookupEnv` + `strconv.ParseBool`
   - 12 env var overrides applied before `flag.Parse()` so CLI flags take precedence
   - Invalid values logged to stderr (logger is not initialized at parse time)

   ### Documentation
   | Doc | Env var documented |
   |-----|--------------------|
   | `docs/installation.md` | Full reference table with all 12 flags |
   | `docs/untaint_controller.md` | `DD_UNTAINT_CONTROLLER_ENABLED` |
   | `docs/datadog_agent_profiles.md` | `DD_AGENT_PROFILE_CONTROLLER_ENABLED` |
   | `docs/introspection.md` | `DD_INTROSPECTION_ENABLED` |
   | `docs/control_plane_monitoring.md` | `DD_INTROSPECTION_ENABLED` (OLM alternative to CSV patch) |
   | `docs/datadog_dashboard.md` | `DD_DASHBOARD_CONTROLLER_ENABLED` |
   | `docs/datadog_monitor.md` | `DD_MONITOR_CONTROLLER_ENABLED` |
   | `docs/datadog_slo.md` | `DD_SLO_CONTROLLER_ENABLED` |
   | `docs/datadog_generic_resource.md` | `DD_GENERIC_RESOURCE_CONTROLLER_ENABLED` |

   ## Test plan
   - [x] `go build ./cmd/main.go` passes
   - [x] `go test ./cmd/...` passes
   - [x] `go vet ./cmd/...` clean
   - [ ] Set `DD_DASHBOARD_CONTROLLER_ENABLED=true` on operator pod, verify controller starts
   - [ ] Set invalid value (e.g. `yes`), verify stderr error message
   - [ ] Set env var + CLI flag, verify CLI flag wins

Original commits:
* f899bf9 Add env var overrides for controller enable flags
* bbdc4b5 Add more options + use small generic helper to parse multiple types + tests
* a050c22 Merge branch 'main' into savec80/feat/env-var-controller-flags
* c04e806 Update docs/control_plane_monitoring.md
* c226883 Update docs/installation.md
* 06f778f Update docs/installation.md
* ea9586c Update docs/installation.md
* b6e7ad0 Update docs/control_plane_monitoring.md
* 7ab35d3 Merge branch 'main' into savec80/feat/env-var-controller-flags

Signed-off-by: Timothée Bavelier <[email protected]>
tbavelier added a commit that referenced this pull request Jun 25, 2026
* Add env var overrides for controller enable flags (#3181)

>[!NOTE]
> This PR is created by pushing locally the commits from #3097 for the purpose of CI. Original commits are preserved with authorship.

>[!IMPORTANT]
> This PR now goes beyond the original controller-only boolean env-var fallback. It centralizes environment override parsing through a small typed helper so options can share the same precedence model: compiled default < environment variable < CLI flag.
>
> The updated implementation supports boolean, string, integer, and duration env vars, while still applying them before `flag.Parse()` so explicit CLI arguments win. In addition to the controller enable flags, it now covers selected non-EDS startup options such as metrics binding, secure metrics, profiling, pprof, leader election, Cilium support, maximum goroutines, controller revisions, and the untaint controller's CSI readiness gate.
>
> EDS flags, log flags, secret backend flags, and `--version` remain CLI-only. Tests were added for env-over-default behavior, CLI-over-env precedence, and invalid env values preserving defaults.

   ### `cmd/main.go`
   - Added `boolFromEnv` helper using `os.LookupEnv` + `strconv.ParseBool`
   - 12 env var overrides applied before `flag.Parse()` so CLI flags take precedence
   - Invalid values logged to stderr (logger is not initialized at parse time)

   ### Documentation
   | Doc | Env var documented |
   |-----|--------------------|
   | `docs/installation.md` | Full reference table with all 12 flags |
   | `docs/untaint_controller.md` | `DD_UNTAINT_CONTROLLER_ENABLED` |
   | `docs/datadog_agent_profiles.md` | `DD_AGENT_PROFILE_CONTROLLER_ENABLED` |
   | `docs/introspection.md` | `DD_INTROSPECTION_ENABLED` |
   | `docs/control_plane_monitoring.md` | `DD_INTROSPECTION_ENABLED` (OLM alternative to CSV patch) |
   | `docs/datadog_dashboard.md` | `DD_DASHBOARD_CONTROLLER_ENABLED` |
   | `docs/datadog_monitor.md` | `DD_MONITOR_CONTROLLER_ENABLED` |
   | `docs/datadog_slo.md` | `DD_SLO_CONTROLLER_ENABLED` |
   | `docs/datadog_generic_resource.md` | `DD_GENERIC_RESOURCE_CONTROLLER_ENABLED` |

   ## Test plan
   - [x] `go build ./cmd/main.go` passes
   - [x] `go test ./cmd/...` passes
   - [x] `go vet ./cmd/...` clean
   - [ ] Set `DD_DASHBOARD_CONTROLLER_ENABLED=true` on operator pod, verify controller starts
   - [ ] Set invalid value (e.g. `yes`), verify stderr error message
   - [ ] Set env var + CLI flag, verify CLI flag wins

Original commits:
* f899bf9 Add env var overrides for controller enable flags
* bbdc4b5 Add more options + use small generic helper to parse multiple types + tests
* a050c22 Merge branch 'main' into savec80/feat/env-var-controller-flags
* c04e806 Update docs/control_plane_monitoring.md
* c226883 Update docs/installation.md
* 06f778f Update docs/installation.md
* ea9586c Update docs/installation.md
* b6e7ad0 Update docs/control_plane_monitoring.md
* 7ab35d3 Merge branch 'main' into savec80/feat/env-var-controller-flags

Signed-off-by: Timothée Bavelier <[email protected]>

* Address env var docs for CLI-pinned flags

---------

Signed-off-by: Timothée Bavelier <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants