Open
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e2f8940593
ℹ️ 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".
🛑 Gate Violations
ℹ️ Info🎯 Code Coverage (details) 🔗 Commit SHA: a93c8bc | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
…guards HandleFinalizer was missing a return on the deletion path, causing reconciliation to continue into create/update logic. Remove the compensating GetDeletionTimestamp checks from all 5 callers, fix SLO deleteResource closure capture, and improve finalizer test coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
|
||
| // 2. Handle finalizer logic. | ||
| if result, err := r.handleFinalizer(reqLogger, instance, r.finalizeDadV2); utils.ShouldReturn(result, err) { | ||
| final := finalizer.NewFinalizer(reqLogger, r.client, r.deleteResource(reqLogger), 0, 0) |
Contributor
There was a problem hiding this comment.
Why don't we pass in an error re-queue period like what's done for datadogslo? Same for all the other migrated controllers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Migrates 5 controllers to use the shared
internal/controller/finalizer/package, eliminating duplicated finalizer boilerplate across DatadogAgent, DatadogAgentInternal, DatadogMonitor, DatadogDashboard, and DatadogGenericResource. (DatadogSLO already used the shared package.)Each controller's
handleFinalizer()andaddFinalizer()methods are replaced with adeleteResource()callback that wraps the existing cleanup logic, passed to the sharedfinalizer.NewFinalizer(...).HandleFinalizer(...).Motivation
CONTP-1335: The finalizer package existed but only DatadogSLO used it. All other controllers copy-pasted the same ~40-60 lines of add/check/remove finalizer scaffolding. This consolidates them.
Changes
Shared
HandleFinalizerowns the full lifecycle. It adds the finalizer on create, runs the delete callback and removes the finalizer on deletion, and returns a requeue result soShouldReturnhandles the early exit. Callers no longer need to checkGetDeletionTimestamp()afterHandleFinalizer. The post-deletion requeue uses the controller's configureddefaultRequeuePeriod:defaultRequeuePeriod(60s), avoiding hot-loop reconcile churn on clusters with many terminating objects.0, getting immediate requeue (same as before).deleteResourcesignature standardized. All controllers now usedeleteResource(logger logr.Logger) finalizer.ResourceDeleteFunc(except DatadogAgentInternal, which gets its logger fromctrl.LoggerFrom(ctx)and usesdeleteResource()).ResourceDeleteFunccontract documented. Added a doc comment explaining the error-handling contract: returning an error blocks deletion and retries; returning nil allows deletion to proceed.No extra requeue after adding finalizer. Previously, controllers returned
Requeue: trueafter adding a finalizer to a new object (triggering an extra reconcile cycle). The shared package returnsctrl.Result{}and lets the current reconcile continue. This is safe becauseclient.Updatereturns the updated object with the new ResourceVersion.Error handling preserved per controller
nil) — finalizer is removed even if the DD API delete failsMinimum Agent Versions
N/A — operator-side refactor only.
Describe your test plan
HandleFinalizerunit tests cover all reachable paths (add finalizer, no-op, delete success, delete failure)Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel