fix: cleanup orphaned components when parent cluster is missing#29
Open
wallyxjh wants to merge 3 commits into
Open
fix: cleanup orphaned components when parent cluster is missing#29wallyxjh wants to merge 3 commits into
wallyxjh wants to merge 3 commits into
Conversation
When a Cluster is deleted but its owned Components still exist without a deletionTimestamp (Running orphans), the componentLoadResourcesTransformer enters an infinite 1s requeue loop because it cannot find the Cluster. PR labring#18 fixed the Terminating orphan case (Components with deletionTimestamp) by handling NotFound in componentDeletionTransformer. However, it did not cover the Running orphan case where the Component has no deletionTimestamp set - this happens when Kubernetes GC fails to complete the cascade deletion. This fix adds orphan detection in componentLoadResourcesTransformer: 1. When Cluster is NotFound, check if the Component has an ownerReference pointing to that Cluster (confirming it's an orphan, not a misconfigured Component). 2. If orphaned, trigger deletion via client.Delete() to set deletionTimestamp. 3. On the next reconcile, componentDeletionTransformer (with PR labring#18 fix) handles the actual cleanup. This eliminates the infinite requeue loop that wastes controller resources and causes log spam across all affected namespaces.
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.
Problem
PR #18 fixed orphaned Component cleanup for the Terminating case (Components with
deletionTimestamp), but did not cover the Running orphan case.When a Cluster is deleted but its owned Components still exist without a
deletionTimestamp, thecomponentLoadResourcesTransformerenters an infinite 1-second requeue loop:This happens when Kubernetes GC fails to complete cascade deletion (e.g. due to timing, force delete, etc.). These orphaned Components waste controller resources and cause log spam across all affected namespaces.
Root Cause
In
transformer_component_load_resources.go, when the Cluster is not found, the code unconditionally returnsnewRequeueError(requeueDuration, err.Error())without checking whether the Component is an orphan:The
componentDeletionTransformer(fixed in PR #18) is skipped entirely because these Components have nodeletionTimestamp.Solution
Added orphan detection in
componentLoadResourcesTransformer:ownerReferencepointing to that Cluster (confirming it is an orphan).client.Delete()to setdeletionTimestamp.componentDeletionTransformer(with PR fix: handle component deletion when parent cluster is missing #18 fix) handles the actual cleanup.Changes
controllers/apps/transformer_component_load_resources.go: AddisOrphanedComponent()andhandleOrphanedComponent(), injectclient.Clientfor direct API calls.controllers/apps/component_controller.go: PassClienttocomponentLoadResourcesTransformer.