← Back to Pull requests

Add the orphan management policy to Datadog resource controllers #3848

Closed
unknown closed this pull request without merging on Nov 30, 2026 15:50 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 14:28 UTC
Author

What does this PR do?

Adds the datadoghq.com/management-policy: orphan annotation to DatadogGenericResource, DatadogMonitor, DatadogDashboard and DatadogSLO. On an annotated CR:

  • The Operator makes no Datadog API call (no create, update, force sync or state refresh) and sets an Orphaned=True condition. The other status fields keep their last values.

  • Deleting the CR removes the finalizer without deleting the Datadog object, and records an Orphaned event.

  • Removing the annotation resumes normal reconciliation.
  • Implementation:

  • Each of the four controllers handles an orphaned CR first, before fetching Datadog credentials, using finalizer.NewOrphanFinalizer. That finalizer never deletes the Datadog object, so the annotation releases a CR even when the keys are missing or can't be decrypted. For DDGR it also doesn't need a handler for spec.type, and updates status directly (requeuing on conflict) so a conflict retry cannot clobber newer status.

  • The shared finalizer gets an opt-in finalizer.WithOrphanPolicy(recorder, onOrphan) option, so the DatadogAgent / DatadogAgentInternal cleanup doesn't change. The onOrphan hook and the Orphaned event run only after the finalizer is removed, so a failed update doesn't repeat them. DatadogMonitor passes a hook that unregisters its metrics forwarder, skips registering a forwarder on create for already-orphaned monitors (monitorMetricsForwarderPredicate), and does not report reconcile metrics while orphaned.

  • The DatadogMonitor and DatadogGenericResource pre-create guards (fresh read from the API server via apiReader) also skip creation when that copy is orphaned, in case the cache doesn't have the annotation yet.

  • The four controllers also reconcile when the annotation changes (datadogResourcePredicate): annotations don't bump metadata.generation, so GenerationChangedPredicate alone misses them.

  • New doc: docs/management_policy.md, linked from the cleanup sections of the four CRD docs.
  • Motivation

    First PR of the stack for CONTP-2281 (design: CONTP-2280 brief). It is the safe handoff that migrating a legacy CR to an adopting DDGR needs, and it fixes the race in today's workaround (remove the finalizer, then delete, while the controller re-adds it). It also pauses a single CR, for example on a passive cluster.

    Stack:
    1. This PR: orphan management policy
    2. #3849: spec.id on DDGR (adoption)
    3. #3850: blocking check against legacy CRs
    4. #3851: kubectl datadog monitor migrate

    Additional Notes

  • An annotation rather than a spec field, so that it works on the legacy CRDs without schema changes and doesn't change spec hashes.

  • An annotation can be added to a CR that is already terminating, which releases a CR stuck on a failing remote delete.

  • Only orphan is recognized. Other values behave as if the annotation were absent.

  • An orphaned DatadogMonitor keeps its last Active/Error conditions, as documented ("other status fields keep their last values").
  • Minimum Agent Versions

    N/A

    Describe your test plan

    On kind against a sandbox org (whole stack deployed): an annotated DatadogDashboard, DatadogSLO and DatadogGenericResource were deleted and their Datadog objects kept. Also a new DDGR was created with the annotation and no backend object was created. Verified logs, orphan state.

    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][1])
  • [1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

    [CONTP-2281]: https://datadoghq.atlassian.net/browse/CONTP-2281?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

    Diff: 507 lines (+380 / -127) across 6 files Reviewer: gabedos Review duration: 7281m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 507 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.373
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3848"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.6% (MEDIUM) · Higher = larger blast radius
    47.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.8% · Safe to merge
    18.8%