Skip to content

reconcile: delete finalizer during reconcile only for resources that do not have any cleanup tasks#1902

Merged
AndrewChubatiuk merged 2 commits intomasterfrom
fix-do-not-delete-finalizer-on-vm-resources
Mar 3, 2026
Merged

reconcile: delete finalizer during reconcile only for resources that do not have any cleanup tasks#1902
AndrewChubatiuk merged 2 commits intomasterfrom
fix-do-not-delete-finalizer-on-vm-resources

Conversation

@AndrewChubatiuk
Copy link
Contributor

@AndrewChubatiuk AndrewChubatiuk commented Feb 28, 2026

currently reconcile functions for VMAgent, VMAuth and VMCluster remove finalizer on non-empty DeletionTimestamp, which may lead to dangling resources. This PR keeps finalizer for these resources when DeletionTimestamp is not empty to let respective controller handle resource removal.

additionally:

  • fixed API templates to remove extra newlines from generated markdown
  • remove finalizer for VMServiceScrape and VMPodscrape during reconcile as both resources have no cleanup actions needed
  • removed impact of metadata change on a need to recreate STS due to PVC changes
  • added RevisionHistoryLimit to a list of STS mutable fields to avoid its unneeded recreation

Summary by cubic

Keep finalizers only on resources that need cleanup (VMAgent, VMAuth, VMCluster), and remove them during reconcile for core K8s and scrape resources to prevent stuck deletions. Diff is now directional (desired vs current) and treats empty and nil equally; StatefulSet recreate checks use Spec-only changes.

  • Bug Fixes

    • Finalizers: remove for ConfigMap/Secret/Service/ServiceAccount/RBAC/HPA/VPA/Ingress/HTTPRoute/PDB/DaemonSet/Deployment/StatefulSet/VMPodScrape/VMServiceScrape; keep for VMAgent/VMAuth/VMCluster. collectGarbage now takes a removeFinalizer flag and waits on deletion without dropping finalizers for VM resources. CHANGELOG updated.
    • StatefulSet: ignore PVC metadata when deciding to recreate; compare Spec only and normalize immutable fields (including RevisionHistoryLimit); log spec_diff.
    • Diff: fix argument order (desired, current); use EquateEmpty so empty slices/maps equal nil; derivative ignores zero values in the desired object; tests updated.
  • Refactors

    • Diff logs: field-level paths with -old +new; reconcilers log as spec_diff/data_diff.
    • Logs/Errors: use NamespacedName.String() across reconcile and vmdistributed; deletion-wait logs show finalizers only when present; API markdown templates trimmed extra newlines.

Written for commit fe8a38a. Summary will update on new commits.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 21 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/CHANGELOG.md">

<violation number="1" location="docs/CHANGELOG.md:23">
P1: Custom agent: **Changelog Review Agent**

This changelog entry violates the mandatory structure: it lacks required issue/PR references and describes internal implementation details instead of a clear user-visible before/after outcome.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@AndrewChubatiuk AndrewChubatiuk force-pushed the fix-do-not-delete-finalizer-on-vm-resources branch 8 times, most recently from 47418d4 to ed152c7 Compare March 1, 2026 05:44
@AndrewChubatiuk AndrewChubatiuk force-pushed the fix-do-not-delete-finalizer-on-vm-resources branch from ed152c7 to 299a15a Compare March 1, 2026 07:57
@AndrewChubatiuk AndrewChubatiuk mentioned this pull request Mar 3, 2026
@AndrewChubatiuk AndrewChubatiuk force-pushed the fix-do-not-delete-finalizer-on-vm-resources branch 3 times, most recently from 56916f3 to 8e418f6 Compare March 3, 2026 15:15
@AndrewChubatiuk AndrewChubatiuk force-pushed the fix-do-not-delete-finalizer-on-vm-resources branch from 5c56c1c to a263dfc Compare March 3, 2026 15:20
specD := diffDeep(actualPVC.Spec, newPVC.Spec)
logMsg := fmt.Sprintf("changes detected for PVC=%s metaDiff=%v, specDiff=%v", newPVC.Name, metaD, specD)
logger.WithContext(ctx).Info(logMsg)
specDiff := diffDeepDerivative(newObj.Spec, existingObj.Spec)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No metadata diff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata is now updated in updatePVC function, before this function only changed PVC size.

@AndrewChubatiuk AndrewChubatiuk force-pushed the fix-do-not-delete-finalizer-on-vm-resources branch from a263dfc to e486f15 Compare March 3, 2026 15:27
@AndrewChubatiuk
Copy link
Contributor Author

@cubic-dev-ai

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Mar 3, 2026

@cubic-dev-ai

@AndrewChubatiuk I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 31 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/CHANGELOG.md">

<violation number="1" location="docs/CHANGELOG.md:27">
P1: Custom agent: **Changelog Review Agent**

This changelog entry doesn’t follow the required structure: it lacks a before/after user‑visible explanation and includes no issue/PR references. It also reads as an internal implementation detail, which is rejected by the changelog rule.</violation>

<violation number="2" location="docs/CHANGELOG.md:27">
P3: Rewrite this changelog entry for clarity and correct grammar so users can clearly understand which resources lose finalizers and which keep them.

(Based on your team's feedback about clarifying behavior and roles in documentation text.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/CHANGELOG.md">

<violation number="1" location="docs/CHANGELOG.md:27">
P1: Custom agent: **Changelog Review Agent**

This changelog entry violates the required structure because it omits issue/PR references (mandatory "References" section). Add relevant links to comply with the changelog format gate.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

* BUGFIX: [vmdistributed](https://docs.victoriametrics.com/operator/resources/vmdistributed/): fix PVC being owned by StatefulSet and top-level object simultaenously. See [#1845](https://github.com/VictoriaMetrics/operator/issues/1845).

* BUGFIX: [vmoperator](https://docs.victoriametrics.com/operator/): remove unneeded finalizer from core K8s resources. See [#835](https://github.com/VictoriaMetrics/operator/issues/835).
* BUGFIX: [vmdistributed](https://docs.victoriametrics.com/operator/resources/vmdistributed/): remove finalizers from VMServiceScrape and VMPodScrape objects, and keep finalizers on VMAgent, VMCluster, and VMAuth when DeletionTimestamp is not empty.
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Custom agent: Changelog Review Agent

This changelog entry violates the required structure because it omits issue/PR references (mandatory "References" section). Add relevant links to comply with the changelog format gate.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/CHANGELOG.md, line 27:

<comment>This changelog entry violates the required structure because it omits issue/PR references (mandatory "References" section). Add relevant links to comply with the changelog format gate.</comment>

<file context>
@@ -24,7 +24,7 @@ aliases:
 * BUGFIX: [vmdistributed](https://docs.victoriametrics.com/operator/resources/vmdistributed/): fix PVC being owned by StatefulSet and top-level object simultaenously. See [#1845](https://github.com/VictoriaMetrics/operator/issues/1845).
 * BUGFIX: [vmoperator](https://docs.victoriametrics.com/operator/): remove unneeded finalizer from core K8s resources. See [#835](https://github.com/VictoriaMetrics/operator/issues/835).
-* BUGFIX: [vmdistributed](https://docs.victoriametrics.com/operator/resources/vmdistributed/): remove  finalizers from VMServiceScrape and VMPodScrape objects and keep them at VMAgent, VMCluster, VMAuth finalizers when DeletionTimestamp is not empty
+* BUGFIX: [vmdistributed](https://docs.victoriametrics.com/operator/resources/vmdistributed/): remove finalizers from VMServiceScrape and VMPodScrape objects, and keep finalizers on VMAgent, VMCluster, and VMAuth when DeletionTimestamp is not empty.
 
 ## [v0.68.1](https://github.com/VictoriaMetrics/operator/releases/tag/v0.68.1)
</file context>
Fix with Cubic

@AndrewChubatiuk AndrewChubatiuk force-pushed the fix-do-not-delete-finalizer-on-vm-resources branch 2 times, most recently from 0a14bcc to afdb35f Compare March 3, 2026 15:40
@vrutkovs
Copy link
Collaborator

vrutkovs commented Mar 3, 2026

Perhaps this fixes #1921? I wonder if we could add test for that?

- convert NamespacedName to string in logs
- update diffDeepDerivative, now slices and maps and considered equal if length of both is 0 (not only of the first maps as it was before), before labels and annotations diff was ignored
- do not take PVC metadata diff into account during checking if STS should be recreated since metadata update is covered by a separate function
- fixed diffDeep and diffDeepDerivative signature, arguments were swapped before
@AndrewChubatiuk AndrewChubatiuk force-pushed the fix-do-not-delete-finalizer-on-vm-resources branch from afdb35f to fe8a38a Compare March 3, 2026 15:52
@AndrewChubatiuk AndrewChubatiuk merged commit 3e5730f into master Mar 3, 2026
2 checks passed
@AndrewChubatiuk AndrewChubatiuk deleted the fix-do-not-delete-finalizer-on-vm-resources branch March 3, 2026 15:52
AndrewChubatiuk added a commit that referenced this pull request Mar 3, 2026
…do not have any cleanup tasks (#1902)

* reconcile: delete finalizer during reconcile only for resources that do not have any cleanup tasks

* reconcile updates

- convert NamespacedName to string in logs
- update diffDeepDerivative, now slices and maps and considered equal if length of both is 0 (not only of the first maps as it was before), before labels and annotations diff was ignored
- do not take PVC metadata diff into account during checking if STS should be recreated since metadata update is covered by a separate function
- fixed diffDeep and diffDeepDerivative signature, arguments were swapped before
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.

2 participants