operator: set status for child objects if no parent objects exist - #2539
AndrewChubatiuk wants to merge 1 commit into
Conversation
db07321 to
be824e7
Compare
be824e7 to
87505c4
Compare
There was a problem hiding this comment.
All reported issues were addressed across 15 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
87505c4 to
6246e27
Compare
There was a problem hiding this comment.
1 issue found across 15 files (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="internal/controller/operator/factory/reconcile/status.go">
<violation number="1" location="internal/controller/operator/factory/reconcile/status.go:243">
P2: When a parent CR is deleted, its Applied condition can remain on the child because no parent reconcile releases it. This function aggregates that stale condition, so an unselected child remains operational or failed instead of becoming ignored; verify that no parents remain before retaining or aggregating persisted Applied conditions.</violation>
</file>
Requires human review: Auto-approval blocked because this review re-detected 2 unresolved issues already reported by Cubic.
Fix all with cubic | Re-trigger cubic
6246e27 to
3226d43
Compare
There was a problem hiding this comment.
7 issues found across 21 files (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="internal/controller/operator/controllers.go">
<violation number="1" location="internal/controller/operator/controllers.go:413">
P1: When cleanup for one scrape kind fails, `releaseScrapeChildStatuses` returns before releasing conditions from the remaining kinds. Since VMAgent/VMSingle finalizers are removed before this helper runs, aggregate the errors while attempting every kind so one transient failure does not leave stale child statuses permanently.</violation>
</file>
<file name="internal/controller/operator/vmservicescrape_controller.go">
<violation number="1" location="internal/controller/operator/vmservicescrape_controller.go:88">
P2: When parent discovery fails, this still recomputes the child status and can write `UpdateStatusIgnored` from empty conditions, falsely reporting that no parent selected the object. Distinguish parent-list failures from per-child reconciliation errors and skip aggregation when discovery is incomplete.</violation>
</file>
<file name="internal/controller/operator/vmstaticscrape_controller.go">
<violation number="1" location="internal/controller/operator/vmstaticscrape_controller.go:67">
P2: When either parent collector fails before discovering parents, this line still recomputes the child status from incomplete conditions. A transient VMAgent list failure can therefore mark a VMStaticScrape as `Ignored` even while a VMAgent exists; run the aggregate sync only after both collectors succeed.</violation>
</file>
<file name="internal/controller/operator/vmsingle_controller.go">
<violation number="1" location="internal/controller/operator/vmsingle_controller.go:107">
P2: When `releaseScrapeChildStatuses` fails, `OnVMSingleDelete` has already removed the VMSingle finalizer, so deletion completes without a retry and child scrape objects retain stale `vmsingleApplied` conditions. Release child statuses before calling `OnVMSingleDelete`, keeping the finalizer until cleanup succeeds.</violation>
</file>
<file name="internal/controller/operator/vmalertmanagerconfig_controller.go">
<violation number="1" location="internal/controller/operator/vmalertmanagerconfig_controller.go:141">
P2: When any parent reconcile fails, this condition discards a child-status synchronization error. Combine both errors (for example with `errors.Join`) so failed child status updates are reported and retried rather than being masked by the parent error.</violation>
</file>
<file name="internal/controller/operator/vmprobe_controller.go">
<violation number="1" location="internal/controller/operator/vmprobe_controller.go:88">
P2: When either parent collection fails, this line still recomputes the child from stale conditions. A transient parent-list failure can therefore write `UpdateStatusIgnored` even when parents exist; sync only after collection succeeds.</violation>
</file>
<file name="internal/controller/operator/vmalert_controller.go">
<violation number="1" location="internal/controller/operator/vmalert_controller.go:102">
P2: The child status release runs after OnVMAlertDelete has removed the VMAlert finalizer. If StatusForChildObjects fails here, the object is already gone and the next reconcile hits NotFound, so the parent condition on any still-attached VMRule is never released and stays stale. Run StatusForChildObjects before finalize.OnVMAlertDelete so a failure keeps the finalizer and lets the reconcile retry.</violation>
</file>
Tip: instead of fixing issues one by one fix them all with cubic
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
3226d43 to
4de7d1c
Compare
There was a problem hiding this comment.
2 issues found across 21 files (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="internal/controller/operator/vmauth_controller.go">
<violation number="1" location="internal/controller/operator/vmauth_controller.go:100">
P2: If the VMAuth name or namespace contains a dot, this parentObject becomes `name.ns.vmauth` with more than three dot-separated parts and childConditionType() panics. On deletion the panic fires before finalize.OnVMAuthDelete, so the finalizer is never removed and the VMAuth remains stuck in terminating state while its VMUser status conditions are never released. Guard against non-three-part names before calling StatusForChildObjects.</violation>
</file>
<file name="internal/controller/operator/vmalert_controller.go">
<violation number="1" location="internal/controller/operator/vmalert_controller.go:99">
P2: When a parent CR name or namespace contains a dot, the `parentObject` string has more than 3 dot-separated segments, so `childConditionType` panics ("BUG: unexpected format...") before the finalizer is removed. A VMAlert named `my.alert` or a namespace like `prod.vm` is a valid object name, so the deletion reconcile panics, the finalizer is never removed, and the parent stays stuck in deletion forever. Derive the parent key in a way that cannot be confused by dots rather than splitting the concatenated string on dots.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
4de7d1c to
14a7de0
Compare
There was a problem hiding this comment.
1 issue found across 21 files (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="internal/controller/operator/vmauth_controller.go">
<violation number="1" location="internal/controller/operator/vmauth_controller.go:101">
P3: On StatusForChildObjects error the branch returns without removing the VMAuth finalizer, so deletion stays pending until a retry succeeds; this mirrors the existing vmagent/vmsingle releaseScrapeChildStatuses pattern and self-heals on the retry. No change required.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
14a7de0 to
720eeee
Compare
There was a problem hiding this comment.
2 issues found across 21 files (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="internal/controller/operator/vmalertmanager_controller.go">
<violation number="1" location="internal/controller/operator/vmalertmanager_controller.go:103">
P1: When the VMAlertmanagerConfig controller or CRD is disabled, this call still lists VMAlertmanagerConfigs and returns a discovery error. The early return prevents `finalize.OnVMAlertManagerDelete`, leaving the VMAlertmanager finalizer and object stuck; skip this cleanup when VMAlertmanagerConfig is disabled, as config generation already does.</violation>
</file>
<file name="internal/controller/operator/controllers.go">
<violation number="1" location="internal/controller/operator/controllers.go:414">
P1: When any scrape CRD is disabled or absent, this call returns `NotFound`, so VMAgent/VMSingle deletion exits before `OnVMAgentDelete`/`OnVMSingleDelete` removes the finalizer. Skip unavailable scrape kinds or ignore their `NotFound` errors during cleanup.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
f333f1a to
ad2c491
Compare
There was a problem hiding this comment.
All reported issues were addressed across 21 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
ad2c491 to
7b0640b
Compare
There was a problem hiding this comment.
All reported issues were addressed across 24 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Fix all with cubic | Re-trigger cubic
7b0640b to
b782b48
Compare
There was a problem hiding this comment.
All reported issues were addressed across 22 files (changes from recent commits).
Tip: instead of fixing issues one by one fix them all with cubic
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
b782b48 to
bcc722d
Compare
|
@cubic-ai-dev |
@AndrewChubatiuk I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
No issues found across 22 files
Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.
Re-trigger cubic
bcc722d to
0214a98
Compare
0214a98 to
fb4d29f
Compare
fb4d29f to
77bb568
Compare
| err = reconcile.SyncAggregatedChildStatus(ctx, r.Client, &instance) | ||
| return | ||
| } | ||
|
|
There was a problem hiding this comment.
Needs if !instance.IsUnmanaged(nil) {
There was a problem hiding this comment.
isUnmanaged is for parent objects, not for child as in this case
| return | ||
| } | ||
|
|
||
| anomalySync.Lock() |
There was a problem hiding this comment.
Needs if !instance.IsUnmanaged(nil) { section
There was a problem hiding this comment.
IsUnmanaged is to identify if parent object can manage exact child object, this is not applicable here
Change should address comment #1181 (comment)