Skip to content

operator: set status for child objects if no parent objects exist - #2539

Open
AndrewChubatiuk wants to merge 1 commit into
masterfrom
set-default-status-for-child-resources
Open

AndrewChubatiuk wants to merge 1 commit into
masterfrom
set-default-status-for-child-resources

Conversation

@AndrewChubatiuk

Copy link
Copy Markdown
Contributor

Change should address comment #1181 (comment)

@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from db07321 to be824e7 Compare August 24, 2026 13:13
Comment thread internal/controller/operator/vmalertmanagerconfig_controller.go Outdated
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from be824e7 to 87505c4 Compare August 28, 2026 14:44

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 15 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread internal/controller/operator/vmpodscrape_controller.go Outdated
Comment thread internal/controller/operator/vmstaticscrape_controller.go Outdated
Comment thread internal/controller/operator/vmnodescrape_controller.go Outdated
Comment thread internal/controller/operator/factory/reconcile/status.go
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from 87505c4 to 6246e27 Compare August 28, 2026 19:26

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread internal/controller/operator/vmanomalyconfig_controller.go Outdated
Comment thread internal/controller/operator/vmrule_controller.go Outdated
Comment thread internal/controller/operator/factory/reconcile/status.go
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from 6246e27 to 3226d43 Compare August 28, 2026 21:11

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread internal/controller/operator/controllers.go Outdated
Comment thread internal/controller/operator/vmservicescrape_controller.go Outdated
Comment thread internal/controller/operator/vmstaticscrape_controller.go Outdated
Comment thread internal/controller/operator/vmsingle_controller.go Outdated
Comment thread internal/controller/operator/vmalertmanagerconfig_controller.go Outdated
Comment thread internal/controller/operator/vmprobe_controller.go Outdated
Comment thread internal/controller/operator/vmalert_controller.go Outdated
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from 3226d43 to 4de7d1c Compare August 28, 2026 22:09

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread internal/controller/operator/vmauth_controller.go
Comment thread internal/controller/operator/vmalert_controller.go Outdated
Comment thread internal/controller/operator/factory/reconcile/status_test.go
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from 4de7d1c to 14a7de0 Compare August 28, 2026 22:30

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

Copy link
Copy Markdown
Contributor

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 (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

Comment thread internal/controller/operator/vmanomalyconfig_controller.go
Comment thread internal/controller/operator/vmauth_controller.go
Comment thread internal/controller/operator/factory/reconcile/status_test.go
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from 14a7de0 to 720eeee Compare August 28, 2026 22:58

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread internal/controller/operator/vmalertmanager_controller.go Outdated
Comment thread internal/controller/operator/controllers.go Outdated
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch 2 times, most recently from f333f1a to ad2c491 Compare September 2, 2026 12:30

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread internal/controller/operator/controllers.go
Comment thread internal/controller/operator/vmalert_controller_test.go
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from ad2c491 to 7b0640b Compare September 2, 2026 13:40

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread internal/controller/operator/vmagent_controller.go
Comment thread internal/controller/operator/factory/vmalert/rules.go
Comment thread internal/controller/operator/factory/vmalertmanager/statefulset.go Outdated
Comment thread internal/controller/operator/controllers.go Outdated
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from 7b0640b to b782b48 Compare September 2, 2026 16:29

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread internal/controller/operator/vmalert_controller.go Outdated
Comment thread internal/controller/operator/vmalertmanager_controller.go Outdated
Comment thread internal/controller/operator/vmanomaly_controller.go Outdated
Comment thread internal/controller/operator/vmanomaly_controller.go Outdated
Comment thread internal/controller/operator/vmagent_controller.go
Comment thread internal/controller/operator/vmauth_controller.go
Comment thread internal/controller/operator/factory/reconcile/status_test.go Outdated
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from b782b48 to bcc722d Compare September 5, 2026 07:07
@AndrewChubatiuk

Copy link
Copy Markdown
Contributor Author

@cubic-ai-dev

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

@cubic-ai-dev

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Comment thread internal/controller/operator/factory/reconcile/status.go
Comment thread internal/controller/operator/vmagent_controller.go Outdated
Comment thread internal/controller/operator/vmalert_controller.go
Comment thread internal/controller/operator/vmscrapeconfig_controller.go Outdated
@vrutkovs
vrutkovs force-pushed the set-default-status-for-child-resources branch from bcc722d to 0214a98 Compare September 9, 2026 08:21
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from 0214a98 to fb4d29f Compare September 10, 2026 08:12
@AndrewChubatiuk
AndrewChubatiuk force-pushed the set-default-status-for-child-resources branch from fb4d29f to 77bb568 Compare September 10, 2026 09:33
err = reconcile.SyncAggregatedChildStatus(ctx, r.Client, &instance)
return
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Needs if !instance.IsUnmanaged(nil) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

isUnmanaged is for parent objects, not for child as in this case

return
}

anomalySync.Lock()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Needs if !instance.IsUnmanaged(nil) { section

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IsUnmanaged is to identify if parent object can manage exact child object, this is not applicable here

@Haleygo Haleygo assigned Haleygo and unassigned vrutkovs Sep 15, 2026
@Haleygo
Haleygo self-requested a review September 15, 2026 07:50

This branch has not been deployed

No deployments
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.

3 participants