Skip to content

Delete stale metrics for not-found Kustomizations - #1770

Draft
zarcen wants to merge 1 commit into
fluxcd:mainfrom
zarcen:fix/delete-metrics-for-removed-kustomizations
Draft

zarcen wants to merge 1 commit into
fluxcd:mainfrom
zarcen:fix/delete-metrics-for-removed-kustomizations

Conversation

@zarcen

@zarcen zarcen commented Oct 12, 2026 •

Copy link
Copy Markdown

Part of #1769

Drop a Kustomization's gotk_reconcile_duration_seconds
series on the NotFound branch of Reconcile, not only when a reconcile
observes the finalizer being removed. Metrics.MetricsRecorder.DeleteDuration
already takes a bare object reference, so no new fluxcd/pkg API is needed.

Test plan: go test ./internal/controller/ -run TestKustomizationReconciler_deleteMetricsOnNotFound
fails on main, passes with this change.

Related PRs

Reconcile only deletes a Kustomization's gotk_reconcile_duration_seconds
series from the deferred metrics call, which never runs when Get
returns NotFound. Objects removed without the controller's own
finalize() completing (for example, a finalizer cleared externally
after its remote target became unreachable) leak their series until
the controller restarts.

MetricsRecorder.DeleteDuration already takes a bare object reference,
so call it directly on the NotFound path. No live object or new
fluxcd/pkg API is needed.

Includes a deterministic test driving two Reconcile calls against a
fake client: the series survives without this fix and is removed
with it.

Signed-off-by: Wei-Chen Chen <zarcen@gmail.com>
Signed-off-by: Wei-Chen Chen <weichen.chen@omniva.com>
Assisted-by: claude-code/claude-sonnet-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant