Skip to content

[CONTP-1589] Add DDGR force sync period configuration#3043

Merged
tbavelier merged 3 commits into
mainfrom
tbavelier/contp-1589
May 27, 2026
Merged

[CONTP-1589] Add DDGR force sync period configuration#3043
tbavelier merged 3 commits into
mainfrom
tbavelier/contp-1589

Conversation

@tbavelier

@tbavelier tbavelier commented May 26, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Adds DD_GENERIC_RESOURCE_FORCE_SYNC_PERIOD to configure the DatadogGenericResource force-sync interval, matching the existing monitor/dashboard/SLO behavior. The value is resolved once when the DDGR controller starts, logged at info level, and reused during reconciliation.

The configured value must be at least one minute. Non-integer values, 0, and negative values are rejected once during controller startup and fall back to the default 60-minute force-sync period.

Also documents DDGR force sync and the existing DDGR namespace watch environment variable.

Motivation

DatadogGenericResource already force-syncs remote resources every 60 minutes, but unlike related Datadog resource controllers, the interval was not configurable. This makes DDGR behavior easier to tune and easier to validate when remote resources drift from Kubernetes source of truth.

Rejecting values below one minute avoids surprising behavior where 0 or negative durations would force an update on every reconciliation loop.

Additional Notes

DD_GENERIC_RESOURCE_WATCH_NAMESPACE already existed and falls back to WATCH_NAMESPACE; this PR only documents that behavior.

The reconcile tests construct the DDGR reconciler through NewReconciler and then override the resource handlers with mocks, so the production force-sync initialization path is covered without calling real Datadog APIs.

Minimum Agent Versions

Are there minimum versions of the Datadog Agent and/or Cluster Agent required?

  • Agent: N/A
  • Cluster Agent: N/A

Describe your test plan

Automated validation:

go test -count=1 ./internal/controller/datadoggenericresource

The tests cover valid force-sync configuration, invalid string values, 0, negative values, and an elapsed force-sync period triggering a remote update.

Manual QA:

  1. Start the operator with the DDGR controller enabled and an invalid force-sync period:

    DD_GENERIC_RESOURCE_FORCE_SYNC_PERIOD=abc

    Verify the operator logs contain this error once during controller startup:

    {"level":"ERROR","logger":"controllers.DatadogGenericResource","msg":"Invalid value for generic resource force sync period. Defaulting to 60 minutes.","error":"strconv.Atoi: parsing \"abc\": invalid syntax"}
  2. Restart the operator with a valid five-minute force-sync period:

    DD_GENERIC_RESOURCE_FORCE_SYNC_PERIOD=5

    Verify the operator logs contain this info log during controller startup:

    {"level":"INFO","logger":"controllers.DatadogGenericResource","msg":"Setting generic resource force sync period","minutes":5}
  3. Apply the notebook DDGR sample:

    kubectl apply -f examples/datadoggenericresource/notebook-sample.yaml

    Wait for the resource to be created and record the Datadog notebook ID:

    kubectl get datadoggenericresource ddgr-notebook-sample -o jsonpath='{.status.id}'
  4. In the Datadog UI, open that notebook and make a visible edit, for example change the notebook name from Example-Notebook to Example-Notebook edited from UI.

  5. Wait at least five minutes, then verify the operator force-sync restored the notebook to the Kubernetes spec from examples/datadoggenericresource/notebook-sample.yaml, including the original notebook name Example-Notebook.

  6. Clean up the sample resource:

    kubectl delete -f examples/datadoggenericresource/notebook-sample.yaml

Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label
  • All commits are signed (see: signing commits)

@datadog-prod-us1-5

datadog-prod-us1-5 Bot commented May 26, 2026

Copy link
Copy Markdown

Code Coverage

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 42.71% (+0.13%)

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

@tbavelier tbavelier added this to the v1.28.0 milestone May 26, 2026
@tbavelier
tbavelier marked this pull request as ready for review May 26, 2026 15:08
@tbavelier
tbavelier requested a review from a team May 26, 2026 15:08
@tbavelier
tbavelier requested a review from a team as a code owner May 26, 2026 15:08
@codecov-commenter

codecov-commenter commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.36%. Comparing base (7a0a7a8) to head (efc450d).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3043      +/-   ##
==========================================
+ Coverage   42.24%   42.36%   +0.12%     
==========================================
  Files         337      337              
  Lines       28951    28964      +13     
==========================================
+ Hits        12230    12272      +42     
+ Misses      15916    15887      -29     
  Partials      805      805              
Flag Coverage Δ
unittests 42.36% <100.00%> (+0.12%) ⬆️

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

Files with missing lines Coverage Δ
...al/controller/datadoggenericresource/controller.go 76.11% <100.00%> (+19.92%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

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

Comment thread internal/controller/datadoggenericresource/controller.go Outdated
@tbavelier
tbavelier force-pushed the tbavelier/contp-1589 branch from f2efadb to 4cfe765 Compare May 26, 2026 15:56
@jeff-morgan-dd jeff-morgan-dd self-assigned this May 26, 2026
@tbavelier
tbavelier merged commit ed139da into main May 27, 2026
38 checks passed
@tbavelier
tbavelier deleted the tbavelier/contp-1589 branch May 27, 2026 07:02
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