Skip to content

Conversation

@MatousJobanek
Copy link
Contributor

@MatousJobanek MatousJobanek commented Dec 19, 2025

SANDBOX-1560

paired with: codeready-toolchain/toolchain-e2e#1241

Summary by CodeRabbit

  • New Features

    • Support for VM stop subresource operations.
  • Improvements

    • Enhanced handling of DataVolume resources during idling and owner scaling.
    • Updated RBAC to include DataVolumes and related PVC permissions.
  • Tests

    • Extended tests to create, track, and assert DataVolume presence and deletion.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 19, 2025

Walkthrough

Adds CDI DataVolume awareness to the idler: RBAC updated for datavolumes, idler treats DataVolume as a deletable owner in scaleOwnerToZero, and tests plus assertion helpers were extended to create, track, and verify DataVolume lifecycle.

Changes

Cohort / File(s) Summary
RBAC & controller cleanup
controllers/idler/idler_controller.go
Removed unused schema import and vmGVR var; updated kubebuilder RBAC annotations to include datavolumes (CDI) and PVCs in pods/replicationcontrollers line; added RBAC note/comment for subresources.kubevirt.io stop subresource.
Owner scaling behavior
controllers/idler/owners.go
scaleOwnerToZero now treats DataVolume like DaemonSet/Job: it calls deleteResource (delete) instead of attempting a scale-down.
Tests: payloads, owners, assertions
controllers/idler/idler_controller_test.go, controllers/idler/owners_test.go, test/idler_assertion.go
Tests create and track a DataVolume in preparePayloads; payloads struct gains dataVolume field; owners tests register DataVolume in APIResourceList; added dataVolumeGVR and DataVolumeExists/DataVolumeDoesNotExist assertion helpers using the dynamic client.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Controller
  participant DynamicClient as "Dynamic Client"
  participant API as "Kubernetes API (cdi.kubevirt.io)"

  Controller->>DynamicClient: discover workload owners
  alt owner is DataVolume
    Controller->>API: DELETE /apis/cdi.kubevirt.io/v1beta1/namespaces/{ns}/datavolumes/{name}
    API-->>DynamicClient: deletion accepted / status
    DynamicClient-->>Controller: deletion response
  else owner is scalable (Deployment/ReplicaSet/etc.)
    Controller->>API: PATCH/scale to 0
    API-->>Controller: scale response
  end
  Controller->>DynamicClient: verify resource removal (tests call DataVolumeExists/DoesNotExist)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review GVR strings and group/version consistency (cdi.kubevirt.io/v1beta1) across tests and runtime calls.
  • Verify delete vs. scale decision logic and ensure finalizer/ownerReference edge cases are handled.
  • Confirm RBAC kubebuilder annotations precisely match required verbs/resources (including subresources.kubevirt.io/virtualmachines/stop).

Possibly related PRs

Suggested reviewers

  • fbm3307
  • jrosental
  • xcoulon

Poem

I hop through manifests at dawn's first glow,
Added DataVolumes so storage can go,
RBAC stamped and tests in place,
A tidy delete — a gentle trace. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: implementing deletion of DataVolumes as part of the idling process for kubevirt resources.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f4a5d0 and 0d62333.

📒 Files selected for processing (5)
  • controllers/idler/idler_controller.go (1 hunks)
  • controllers/idler/idler_controller_test.go (6 hunks)
  • controllers/idler/owners.go (1 hunks)
  • controllers/idler/owners_test.go (2 hunks)
  • test/idler_assertion.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build & push operator bundles & dashboard image for e2e tests
🔇 Additional comments (9)
controllers/idler/idler_controller.go (2)

160-171: LGTM! DataVolume test configuration follows established patterns.

The test configuration correctly treats DataVolume like DaemonSet and Job (exists/does not exist assertions rather than scaling), which aligns with the deletion behavior in owners.go.


449-454: The DataVolume API version cdi.kubevirt.io/v1beta1 is correct. This is the current stable API version used throughout KubeVirt CDI documentation and examples. No newer v1 stable version exists.

test/idler_assertion.go (1)

301-315: LGTM! Assertion helpers follow established patterns.

The DataVolume assertion methods correctly mirror the implementation for Job and DaemonSet assertions, using the dynamic client with appropriate error handling.

controllers/idler/idler_controller_test.go (2)

999-1007: LGTM! DataVolume test payload creation is comprehensive.

The DataVolume is properly created with:

  • Correct API version (cdi.kubevirt.io/v1beta1)
  • Proper namespace and naming
  • Associated controlled pods via owner references

This follows the established pattern for other resource types in the test suite.


203-205: LGTM! Test assertions properly verify DataVolume lifecycle.

The test assertions comprehensively cover DataVolume behavior in both idled and running scenarios, following the same pattern as DaemonSet and Job resources.

Also applies to: 333-333, 551-551

controllers/idler/owners.go (1)

63-64: LGTM! DataVolume correctly handled via deletion.

DataVolumes, like DaemonSets and Jobs, don't support scaling operations and are appropriately deleted instead. This implementation aligns with the test expectations and the resource's capabilities.

controllers/idler/owners_test.go (3)

160-171: LGTM! DataVolume test configuration follows the correct pattern.

The test configuration correctly models DataVolume as a delete-rather-than-scale resource, consistent with DaemonSet and Job. The assertion hooks properly verify existence during scale-up and deletion during scale-down.


449-454: No action required—the DataVolume APIResource is correctly using cdi.kubevirt.io/v1beta1, which is the current stable API version for KubeVirt CDI DataVolumes.


443-443: The hard-coded "kubevirt.io/v1" is intentional and appropriate for this test fixture. The variable vmGVR does not exist in the codebase, so there was no previous dynamic reference. The noAAPResourceList() function builds test data for fake discovery responses, where well-known KubeVirt and CDI API versions are appropriately hard-coded as static test fixtures. The dynamically discovered resources (lines 455+) correctly use gvk.GroupVersion().String() and gvr.GroupVersion().String(), which is a deliberate distinction, not an inconsistency.

Likely an incorrect or invalid review comment.

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.58%. Comparing base (7f4a5d0) to head (dba7e2a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #719      +/-   ##
==========================================
+ Coverage   82.53%   82.58%   +0.04%     
==========================================
  Files          48       48              
  Lines        3596     3606      +10     
==========================================
+ Hits         2968     2978      +10     
  Misses        477      477              
  Partials      151      151              
Files with missing lines Coverage Δ
controllers/idler/idler_controller.go 92.40% <ø> (ø)
controllers/idler/owners.go 97.46% <100.00%> (ø)
test/idler_assertion.go 94.80% <100.00%> (+0.23%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@openshift-ci
Copy link

openshift-ci bot commented Dec 19, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, MatousJobanek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [MatousJobanek,alexeykazakov]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants