Skip to content

Conversation

@AndrewChubatiuk
Copy link
Contributor

@AndrewChubatiuk AndrewChubatiuk commented Jan 31, 2026

related to #1707

  • removed returning errRecreate inside reconcile functions, which was moved freeIfneeded function (which is now private and resides inside reconcile package), it now returns errRecreate if deleteTimestamp is not zero
  • removed complex merging metadata logic, which was needed before managedMetadata was introduced

Summary by cubic

Fixes finalizer cleanup by centralizing freeIfNeeded across reconcilers to remove stale finalizers and recreate deleted resources. Prevents resources from getting stuck and adds Ingress reconciliation plus simpler rule config updates.

  • Bug Fixes
    • Unified freeIfNeeded usage across ConfigMap, Secret, Service, ServiceAccount, Role/RoleBinding/ClusterRole/ClusterRoleBinding, Deployment, DaemonSet, StatefulSet (+ PVC expand), HPA, PDB, HTTPRoute, Ingress, and VMServiceScrape to avoid hanging recreations.
    • Refactored helpers and simplified signatures (dropped prev object plumbing), aligned variable names (newObj/existingObj), tightened equality checks; VMAlert rules now use the ConfigMap reconciler and reload only on changes; updated changelog.

Written for commit da40408. 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 16 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


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

<violation number="1" location="docs/CHANGELOG.md:29">
P1: Rule violated: **Changelog Review Agent**

Changelog entries must include reference links and a user‑centric before/after explanation. This entry is missing any issue/PR link and focuses on internal implementation details (function ordering/finalizer handling) instead of a user-visible impact description, violating the changelog structure requirements (References + User-centric explanation clauses).</violation>
</file>

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

@AndrewChubatiuk AndrewChubatiuk changed the title reconcile: changed order of FreeIfNeeded and non empty deletionTimestamp check reconcile: refactor freeing old resource finalizer removal Jan 31, 2026
@AndrewChubatiuk AndrewChubatiuk force-pushed the fix-finalizer-cleanup branch 2 times, most recently from 389665c to 9f07ff5 Compare February 1, 2026 06:12
@AndrewChubatiuk
Copy link
Contributor Author

@cubic-dev-ai review this PR

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Feb 1, 2026

@cubic-dev-ai review this PR

@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.

4 issues found across 24 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="internal/controller/operator/factory/reconcile/vmservicescrape.go">

<violation number="1" location="internal/controller/operator/factory/reconcile/vmservicescrape.go:43">
P3: Spec diff is computed after overwriting existingObj.Spec, so the log always shows an empty diff and loses diagnostic value. Compute the diff before assigning to existingObj.Spec.</violation>
</file>

<file name="internal/controller/operator/factory/reconcile/configmap.go">

<violation number="1" location="internal/controller/operator/factory/reconcile/configmap.go:24">
P1: Handle non-NotFound errors from the initial Get. Otherwise, API errors are swallowed and the reconciler proceeds with an empty object, which can lead to incorrect updates or misleading retries.</violation>
</file>

<file name="internal/controller/operator/factory/reconcile/httproute.go">

<violation number="1" location="internal/controller/operator/factory/reconcile/httproute.go:40">
P2: Use DeepDerivative here to ignore controller-defaulted fields; DeepEqual will continually detect diffs once defaults are applied to the live object.</violation>
</file>

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

<violation number="1" location="docs/CHANGELOG.md:29">
P2: Rule violated: **Changelog Review Agent**

Changelog entry doesn’t follow the required user‑centric structure: it cites an internal implementation detail (“previous resource finalizer”) and doesn’t explicitly describe the before/after user-visible behavior. The changelog rule requires a before/after explanation without internal details.</violation>
</file>

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

@AndrewChubatiuk
Copy link
Contributor Author

@cubic-dev-ai review this PR

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Feb 1, 2026

@cubic-dev-ai review this PR

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

@AndrewChubatiuk AndrewChubatiuk changed the title reconcile: refactor freeing old resource finalizer removal reconcile: refactor freeing recreated resource finalizer removal Feb 1, 2026
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 24 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="internal/controller/operator/factory/reconcile/httproute.go">

<violation number="1" location="internal/controller/operator/factory/reconcile/httproute.go:43">
P2: The strict DeepEqual on labels defeats the existing metadata-merge logic that preserves external labels, so any label added by another controller will force updates every reconcile. Rely on isObjectMetaEqual (which already handles label/annotation differences) to avoid update churn.</violation>
</file>

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

@AndrewChubatiuk
Copy link
Contributor Author

@cubic-dev-ai review this PR

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Feb 1, 2026

@cubic-dev-ai review this PR

@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 38 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="internal/controller/operator/factory/reconcile/hpa.go">

<violation number="1" location="internal/controller/operator/factory/reconcile/hpa.go:36">
P3: `spec_diff` is always empty because the diff is computed after `existingObj.Spec` is overwritten with `newObj.Spec`. Capture the diff before mutating `existingObj.Spec` so the log reflects the actual changes.</violation>
</file>

<file name="internal/controller/operator/factory/vmalert/rules.go">

<violation number="1" location="internal/controller/operator/factory/vmalert/rules.go:53">
P2: Reconcile now overwrites existing ConfigMap annotations with nil, so third‑party annotations on rule ConfigMaps are lost on update. The previous logic merged current annotations; this change causes annotation loss.</violation>
</file>

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

@AndrewChubatiuk
Copy link
Contributor Author

@cubic-dev-ai review this PR

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Feb 1, 2026

@cubic-dev-ai review this PR

@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.

1 issue found across 49 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="internal/controller/operator/factory/reconcile/configmap.go">

<violation number="1" location="internal/controller/operator/factory/reconcile/configmap.go:32">
P2: BinaryData changes are ignored. The reconcile compares/updates only Data/Labels/Annotations, so any BinaryData updates will never be applied. Include BinaryData in the equality check and copy it onto the existing object before update.</violation>
</file>

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

logger.WithContext(ctx).Info(fmt.Sprintf("updating ConfigMap %s configuration", newCM.Name))

return rclient.Update(ctx, newCM)
if equality.Semantic.DeepEqual(newObj.Data, existingObj.Data) &&
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 1, 2026

Choose a reason for hiding this comment

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

P2: BinaryData changes are ignored. The reconcile compares/updates only Data/Labels/Annotations, so any BinaryData updates will never be applied. Include BinaryData in the equality check and copy it onto the existing object before update.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/controller/operator/factory/reconcile/configmap.go, line 32:

<comment>BinaryData changes are ignored. The reconcile compares/updates only Data/Labels/Annotations, so any BinaryData updates will never be applied. Include BinaryData in the equality check and copy it onto the existing object before update.</comment>

<file context>
@@ -7,41 +7,39 @@ import (
-	logger.WithContext(ctx).Info(fmt.Sprintf("updating ConfigMap %s configuration", newCM.Name))
-
-	return rclient.Update(ctx, newCM)
+		if equality.Semantic.DeepEqual(newObj.Data, existingObj.Data) &&
+			equality.Semantic.DeepEqual(newObj.Labels, existingObj.Labels) &&
+			equality.Semantic.DeepEqual(newObj.Annotations, existingObj.Annotations) {
</file context>
Fix with Cubic

@AndrewChubatiuk
Copy link
Contributor Author

@cubic-dev-ai review this PR

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Feb 1, 2026

@cubic-dev-ai review this PR

@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.

1 issue found across 49 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="internal/controller/operator/factory/reconcile/httproute.go">

<violation number="1" location="internal/controller/operator/factory/reconcile/httproute.go:38">
P2: Overwriting labels/annotations drops third‑party metadata. Use the existing merge logic to preserve unmanaged labels/annotations instead of replacing the maps outright.</violation>
</file>

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


return rclient.Update(ctx, newHTTPRoute)
specDiff := diffDeepDerivative(newObj.Spec, existingObj.Spec)
existingObj.Labels = newObj.Labels
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 1, 2026

Choose a reason for hiding this comment

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

P2: Overwriting labels/annotations drops third‑party metadata. Use the existing merge logic to preserve unmanaged labels/annotations instead of replacing the maps outright.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At internal/controller/operator/factory/reconcile/httproute.go, line 38:

<comment>Overwriting labels/annotations drops third‑party metadata. Use the existing merge logic to preserve unmanaged labels/annotations instead of replacing the maps outright.</comment>

<file context>
@@ -10,50 +10,35 @@ import (
-
-		return rclient.Update(ctx, newHTTPRoute)
+		specDiff := diffDeepDerivative(newObj.Spec, existingObj.Spec)
+		existingObj.Labels = newObj.Labels
+		existingObj.Annotations = newObj.Annotations
+		existingObj.Spec = newObj.Spec
</file context>
Fix with Cubic

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