Skip to content

Add env var overrides for controller enable flags#3181

Merged
tbavelier merged 2 commits into
mainfrom
savec80/feat/env-var-controller-flags
Jun 25, 2026
Merged

Add env var overrides for controller enable flags#3181
tbavelier merged 2 commits into
mainfrom
savec80/feat/env-var-controller-flags

Conversation

@tbavelier

@tbavelier tbavelier commented Jun 19, 2026

Copy link
Copy Markdown
Member

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.

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

@tbavelier tbavelier added this to the v1.29.0 milestone Jun 19, 2026
@tbavelier tbavelier added the enhancement New feature or request label Jun 19, 2026
@datadog-datadog-prod-us1

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

Copy link
Copy Markdown

Pipelines  Code Coverage

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

DataDog/datadog-operator | e2e: [1.19]   View in Datadog   GitLab

ℹ️ Info

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 44.89% (+0.24%)

Useful? React with 👍 / 👎

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

@codecov-commenter

codecov-commenter commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.27%. Comparing base (9d4cf55) to head (a050c22).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3181      +/-   ##
==========================================
+ Coverage   44.03%   44.27%   +0.23%     
==========================================
  Files         377      377              
  Lines       30713    30763      +50     
==========================================
+ Hits        13525    13620      +95     
+ Misses      16300    16255      -45     
  Partials      888      888              
Flag Coverage Δ
unittests 44.27% <100.00%> (+0.23%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/main.go 29.94% <100.00%> (+23.26%) ⬆️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d4cf55...a050c22. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tbavelier
tbavelier marked this pull request as ready for review June 19, 2026 14:58
@tbavelier
tbavelier requested a review from a team June 19, 2026 14:58
@tbavelier
tbavelier requested a review from a team as a code owner June 19, 2026 14:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a050c224b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/installation.md Outdated
Comment on lines +186 to +187
| Pprof | `--pprof` | `DD_PPROF_ENABLED` | `false` |
| Leader election | `--enable-leader-election` | `DD_LEADER_ELECTION_ENABLED` | `true` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Don’t list env toggles for CLI-pinned flags

In the default manager/OLM manifests I checked (config/manager/manager.yaml:39-41 and bundle/manifests/datadog-operator.clusterserviceversion.yaml:913-915), the operator is always started with --enable-leader-election and --pprof. Since the new parser applies env values before flag.Parse() and explicitly gives CLI args precedence, setting DD_LEADER_ELECTION_ENABLED=false or DD_PPROF_ENABLED=false in an OLM Subscription will be overwritten by those existing args, so users following this table cannot actually disable those options without patching container args.

Useful? React with 👍 / 👎.

@janine-c janine-c left a comment

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.

Looks great! I just have some very minor writing suggestions I noticed.

For full compliance with the docs team writing guide, I'd get an agent to go through and replace the word via with something like using or through, but I don't think that's a showstopper in this context.

Comment thread docs/control_plane_monitoring.md Outdated
Comment thread docs/control_plane_monitoring.md Outdated
Comment thread docs/installation.md Outdated
Comment thread docs/installation.md Outdated
Comment thread docs/installation.md Outdated
>[!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
tbavelier force-pushed the savec80/feat/env-var-controller-flags branch from 7ab35d3 to 03d1e1a Compare June 25, 2026 08:01
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.

4 participants