fix: preserve remote resource IDs on stale status conflicts #3654
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 · 536 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.376
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3654"
general
weight: 0.35
gabedos
What does this PR do?
Preserve a newly persisted remote resource ID when an ID-less status write conflicts in DatadogMonitor or DatadogGenericResource. The retry keeps the entire newer status instead of replacing it with stale error status.
Motivation
A reconcile can read cached status without an ID after a successful create has already persisted one. A duplicate-create 400 followed by a Kubernetes 409 could then overwrite the stored ID, breaking subsequent updates and deletion.
Additional Notes
12345, which is deleted through the Datadog UI. The operator detects the missing monitor and recreates it; the new ID is persisted. If an update-time 404 first requires clearing the old ID, that reset remains allowed when the fetched ID matches the ID the reconcile originally observed. The guard does not block successful writes containing the new ID.Minimum Agent Versions
Agent: N/A
Cluster Agent: N/A
Describe your test plan
Manual QA steps (executed on
kindclusterlocal-k8swith the PR image; backend verification/deletion used the Datadog HTTP API):1. Deploy with valid Datadog credentials,
DD_MONITOR_CONTROLLER_ENABLED=true,DD_GENERIC_RESOURCE_CONTROLLER_ENABLED=true, andDD_MONITOR_MAX_CONCURRENT_RECONCILES=3.2. Create a uniquely named monitor using
examples/datadogmonitor/metric-monitor-test.yamlin a watched namespace:Verify
status.idis nonzero,status.primaryis true, and the monitor exists in the Datadog UI. Record its ID.3. Change
spec.messageand reapply. Verify the message changes on the same monitor andstatus.idremains unchanged; no second monitor is created.4. Delete that monitor through the Datadog UI or
DELETE /api/v1/monitor/{id}while keeping the CR. Changespec.messageagain and reapply to trigger reconciliation. Verify the operator recreates the monitor, persists a new nonzero ID, and later reconciles retain it. Change the message once more and confirm the recreated monitor is updated with the same new ID.5. Delete the CR:
Verify the CR is removed without a stuck finalizer and the recreated monitor disappears from Datadog.
6. (Optional) Repeat creation, message update, backend deletion/recreation, and CR deletion with
examples/datadoggenericresource/monitor-sample.yaml(substitute valid constituent monitor IDs in its composite query and choose a unique monitor name). Verifystatus.idis populated,status.syncStatusbecomesOK, updates retain the ID, recreation persists a new ID, and CR deletion removes the remote monitor.Live race checks completed:
0was persisted; restarting the deployed operator recreated the monitor and persisted a new ID.Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel[1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits