Skip to content

fix(argocd): the cluster app-of-apps leaves argo cd's pre-delete finalizers on child applications, so k8s-monitoring stops resyncing every five minutes #1674

Closed

Description

@dan-petty

Friction

The app-of-apps cluster re-applies Application k8s-monitoring every five minutes, around the clock, and stays OutOfSync most of the time (known K3). Each apply strips the two pre-delete finalizers that Argo CD adds because the k8s-monitoring chart ships a PreDelete hook; Argo CD then adds them back. cluster's sync status can no longer be trusted to show real drift, and for up to about 2m15s of every cycle k8s-monitoring has no pre-delete finalizer, so deleting it in that window skips the chart's clean-up Job and leaves resources hanging in Terminating.

Evidence

Live, read-only, 2026-10-17 (Argo CD v3.5.3; main = 3dd7fa6):

  • argocd-application-controller-0 logged "Applying resource Application/k8s-monitoring" 110 times in about 9h35m since its 12:27Z restart, 12 times an hour (at :x0:19 and :x5:19); every other child Application was applied once. The API server warning "metadata.finalizers: "pre-delete-finalizer.argocd.argoproj.io": prefer a domain-qualified finalizer name" appears after each apply (107 times).
  • Events on cluster cycle: "Initiated automated sync", "Partial sync operation ... succeeded", Synced, then OutOfSync 0s to 2m15s later. Only Application/k8s-monitoring is OutOfSync.
  • Sampling Application argocd/k8s-monitoring every 30s: at 22:01:47Z only resources-finalizer.argocd.argoproj.io; at 22:02:18Z also pre-delete-finalizer.argocd.argoproj.io and pre-delete-finalizer.argocd.argoproj.io/cleanup.
  • The argocd.argoproj.io/hydrate annotation is not the cause: 21 of 23 Applications carry it and only k8s-monitoring drifts.
  • Deployment monitoring/k8s-monitoring-alloy-operator carries k8s.grafana.com/finalizer, which only the chart's pre-delete Job removes; Alloy CRs k8s-monitoring-alloy-{logs,metrics,singleton} carry helm.sdk.operatorframework.io/uninstall-release.
  • cluster's status.history still ends at id 13 (3dd7fa6): self-heal partial syncs do not add history.

Repo and source:

  • k8s/argocd/bootstrap/cluster.yaml:20-32 ignores only /spec/source/kustomize on devops and ingress, with RespectIgnoreDifferences=true at :37-38. k8s/argocd/apps/k8s-monitoring.yaml:6-7 lists only the resources finalizer.
  • Chart k8s-monitoring 4.5.2 templates/hooks/pre-delete_remove-alloy-and-finalizer.yaml ships the Job and its RBAC as helm.sh/hook: pre-delete, which Argo CD maps to PreDelete (controller/hook.go:33-35).
  • Argo CD v3.5.3 controller/appcontroller.go:1974-1986 adds both pre-delete finalizers when rendered manifests contain PreDelete hooks; :1323 runs PreDelete hooks only if the finalizer is present; the re-add is skipped once a deletionTimestamp is set (comment at :1973).
  • tests/test_k8s_argocd_apps.py (around 395-417, test_the_app_of_apps_keeps_the_hosts_deploy_stack_sets_on_the_homelab_applications) asserts ignoreDifferences equals exactly the two kustomize entries.
  • docs/agent/tasks/task-913-deploy-stack-applies-the-monitoring-perimeter.md:65 has a pending check that this hook Job completes on removal.

Remedy

  1. Tests first: extend the test above to expect the new entry, and add a test that the jq expression selects pre-delete-finalizer.argocd.argoproj.io, pre-delete-finalizer.argocd.argoproj.io/cleanup and the matching post-delete names, and does not select resources-finalizer.argocd.argoproj.io (evaluate it with a jq library already available, or assert the exact expression string if none is).
  2. k8s/argocd/bootstrap/cluster.yaml: after the two kustomize entries, add one entry for every child Application:
    group: argoproj.io, kind: Application, jqPathExpressions: ['.metadata.finalizers[] | select(startswith("pre-delete-finalizer.argocd.argoproj.io") or startswith("post-delete-finalizer.argocd.argoproj.io"))'], with a comment citing Argo CD's PreDelete finalizers. Keep RespectIgnoreDifferences=true; for a CRD, Argo CD then carries the live finalizers into the applied object.
  3. Do not ignore /metadata/finalizers wholesale (git would stop enforcing the resources finalizer), and do not hard-code the pre-delete finalizers in k8s-monitoring.yaml (Argo CD removes them itself when a chart drops its hook, which would loop the other way).
  4. changelog.d/<issue>.md under ### Fixed.

Verification after the merge: kubectl -n argocd get events --field-selector involvedObject.name=cluster shows no "Initiated automated sync" every five minutes, cluster stays Synced, and k8s-monitoring keeps all three finalizers.

Priority: P2. Severity medium: nothing is broken today, but removal is racy and the root app's status hides drift.

Proposed design

Problem statement

The app-of-apps 'cluster' re-applies the Application 'k8s-monitoring' every five minutes, causing Argo CD to repeatedly strip and re-add pre-delete finalizers. This leads to constant OutOfSync status for k8s-monitoring, hiding real drift and creating a race condition during deletion where resources may be left in Terminating state.

Acceptance criteria

  • Criterion 1: The cluster app-of-apps no longer repeatedly applies the k8s-monitoring Application
    Verification: Verify that kubectl -n argocd get events --field-selector involvedObject.name=cluster shows no 'Initiated automated sync' every five minutes
  • Criterion 2: The k8s-monitoring Application maintains all three finalizers (resources-finalizer.argocd.argoproj.io, pre-delete-finalizer.argocd.argoproj.io, and pre-delete-finalizer.argocd.argoproj.io/cleanup) consistently
    Verification: Verify that kubectl -n argocd get application k8s-monitoring -o jsonpath='{.metadata.finalizers}' shows all three finalizers present
  • Criterion 3: The cluster Application stays Synced instead of constantly going OutOfSync for k8s-monitoring
    Verification: Verify that the cluster Application status remains Synced over a period of time

Key questions

  • What specific finalizers are being stripped and re-added by Argo CD during the sync process?: The pre-delete finalizers 'pre-delete-finalizer.argocd.argoproj.io' and 'pre-delete-finalizer.argocd.argoproj.io/cleanup' are stripped and re-added when Argo CD applies the k8s-monitoring Application manifest. [sources: k8s/argocd/bootstrap/cluster.yaml:20-32]
  • What is the current structure of ignoreDifferences in cluster.yaml?: The current ignoreDifferences section only ignores /spec/source/kustomize for devops and ingress Applications, with RespectIgnoreDifferences=true at line 37-38. [sources: k8s/argocd/bootstrap/cluster.yaml:20-32]
  • What is the current finalizer configuration in k8s-monitoring.yaml?: The k8s-monitoring.yaml currently lists only the resources-finalizer.argocd.argoproj.io finalizer. [sources: k8s/argocd/apps/k8s-monitoring.yaml:6-7]
  • What test verifies the current ignoreDifferences behavior?: The test test_the_app_of_apps_keeps_the_hosts_deploy_stack_sets_on_the_homelab_applications in tests/test_k8s_argocd_apps.py asserts that ignoreDifferences equals exactly the two kustomize entries. [sources: tests/test_k8s_argocd_apps.py:395-417]
  • Should we extend the existing test to verify the new finalizer behavior?: Yes, we should extend the test to expect the new entry for pre-delete finalizers and add a test that verifies the jq expression selects the correct pre-delete and post-delete finalizers. (proposed)
  • Should we modify the ignoreDifferences in cluster.yaml to include pre-delete finalizers?: Yes, we should add entries for pre-delete and post-delete finalizers in cluster.yaml's ignoreDifferences section to prevent the constant stripping and re-adding. (proposed)
  • Should we continue ignoring /metadata/finalizers wholesale?: No, we should not ignore /metadata/finalizers wholesale as this would stop enforcing the resources finalizer and hard-code pre-delete finalizers that may change. (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    on Oct 18, 2026
  2. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Type: type/bug. The candidate describes a bug where Argo CD's pre-delete finalizers are being stripped from child applications, causing resync issues.
    • Priority: P1-High. This bug affects the reliability and correctness of application deletion in the cluster, causing resources to hang in Terminating state.
    • Value: High. Fixing this ensures proper cleanup of resources during application deletion, which is critical for system stability and data integrity.
    • Effort: Medium. Requires modifying the app-of-apps configuration and updating tests to ensure finalizers are respected during sync operations.
  3. dan-petty commented on Oct 18, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 25e2cda (see proposed design in issue body).

  4. added this to the v0.2.37 milestone on Oct 19, 2026
  5. added
    status/in-progress
    status/in-review
    and removed
    status/in-progress
    on Oct 19, 2026
  6. dan-petty commented on Oct 20, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1713, merged into release/v0.2.37 as 8bdca6e.

    Closes #1674

    6 file(s) changed.

    How it was verified

    Check runs at 8e0a2c0:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Rule Pack Tests: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Fail-to-Pass Check: pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1674-argocd-pre-delete-finalizers.md:

    No Acceptance Criteria section.

  7. removed
    status/in-review
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source/agenttype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions