Skip to content

OCPBUGS-101813: only block vSphere machine deletion for VMDK-backed v… - #1528

Open
jcpowermac wants to merge 2 commits into
openshift:mainfrom
jcpowermac:ocpbugs-101813-volume-type-filtering
Open

OCPBUGS-101813: only block vSphere machine deletion for VMDK-backed v…#1528
jcpowermac wants to merge 2 commits into
openshift:mainfrom
jcpowermac:ocpbugs-101813-volume-type-filtering

Conversation

@jcpowermac

@jcpowermac jcpowermac commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

…olumes

The nodeHasVolumesAttached() check was volume-type-agnostic, blocking machine deletion for any attached volume. This caused indefinite blocking when non-VMDK volumes (NFS, iSCSI, etc.) were attached, since DaemonSet pods with these volumes remain Running and never get evicted.

The VMDK data loss risk only applies to vSphere-backed volumes. This change filters by VolumeAttachment.Spec.Attacher to only block for:

  • csi.vsphere.vmware.com (vSphere CSI)
  • kubernetes.io/vsphere-volume (vSphere in-tree)

Non-vSphere volumes no longer block deletion. Conservative behavior: if VolumeAttachment lookup fails, treat as vSphere-backed and block.

Includes unit tests for volume type filtering and e2e test for NFS volume deletion scenario.

Summary by CodeRabbit

  • Bug Fixes

    • Machine deletion now proceeds when only non-vSphere volumes, such as NFS-backed storage, are attached.
    • Deletion remains safely blocked while vSphere-managed, unidentified, or unresolved volumes may still be attached.
    • Mixed volume attachments are handled correctly, preventing unnecessary deletion delays while protecting active vSphere storage.
  • Tests

    • Added coverage for NFS, vSphere, mixed, unknown, and other CSI volume scenarios.
    • Added end-to-end validation for deleting machines with non-vSphere volumes.

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 3, 2026
@openshift-ci

openshift-ci Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Aug 3, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@jcpowermac: This pull request references Jira Issue OCPBUGS-101813, which is invalid:

  • expected the bug to target the "5.0.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

…olumes

The nodeHasVolumesAttached() check was volume-type-agnostic, blocking machine deletion for any attached volume. This caused indefinite blocking when non-VMDK volumes (NFS, iSCSI, etc.) were attached, since DaemonSet pods with these volumes remain Running and never get evicted.

The VMDK data loss risk only applies to vSphere-backed volumes. This change filters by VolumeAttachment.Spec.Attacher to only block for:

  • csi.vsphere.vmware.com (vSphere CSI)
  • kubernetes.io/vsphere-volume (vSphere in-tree)

Non-vSphere volumes no longer block deletion. Conservative behavior: if VolumeAttachment lookup fails, treat as vSphere-backed and block.

Includes unit tests for volume type filtering and e2e test for NFS volume deletion scenario.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign racheljpg for approval. For more information see the Code Review Process.

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

Details Needs approval from an approver in each of these files:

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

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The vSphere reconciler now classifies attached volumes by VolumeAttachment.Spec.Attacher. vSphere volumes block machine deletion. Recognized non-vSphere volumes do not. Unit and end-to-end tests cover these paths.

Changes

vSphere volume-aware machine deletion

Layer / File(s) Summary
Classify attached volumes
pkg/controller/vsphere/reconciler.go
The reconciler looks up VolumeAttachment objects, correlates direct and hashed attachment names, and classifies vSphere, non-vSphere, and unknown attachers.
Validate deletion decisions
pkg/controller/vsphere/reconciler_test.go
Table-driven tests cover vSphere CSI, in-tree vSphere, non-vSphere, mixed, missing, empty, and unknown attachments.
Validate non-VMDK machine deletion
test/e2e/vsphere/machines.go, ocpbugs-101813.md
The end-to-end test mounts an NFS-backed PVC, deletes the machine, and verifies node recovery. The bug report documents the behavior and test scenarios.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Reconciler
  participant KubernetesAPI
  participant vCenter
  Reconciler->>KubernetesAPI: Look up VolumeAttachment objects
  KubernetesAPI-->>Reconciler: Return attachers or lookup results
  Reconciler->>Reconciler: Classify attached volumes
  Reconciler->>vCenter: Delete VM when no vSphere volume blocks deletion
  Reconciler-->>Reconciler: Requeue when a vSphere volume blocks deletion
Loading

Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 3 warnings)

Check name Status Explanation Resolution
No-Sensitive-Data-In-Logs ❌ Error New logs include nodeName, machineName, and volume/VolumeAttachment names; nodeName can be an internal hostname and resource names can expose customer identifiers. Do not log raw node, machine, or volume identifiers. Log only counts and attacher types, or use approved redaction or hashing.
Test Structure And Quality ⚠️ Warning The new Ginkgo It has many bare Expect(err).NotTo(HaveOccurred()) assertions, uses context.Background for API calls, and only defers namespace deletion; machine cleanup is absent on failure. Add assertion messages and bounded API contexts. Use AfterEach to delete the machine and test resources, and wait for cleanup to complete.
Single Node Openshift (Sno) Test Compatibility ⚠️ Warning The new unguarded serial Ginkgo test creates and deletes a machine, waits for its node, and asserts node count restoration; this tests node scaling and assumes a non-SNO topology. Add [Skipped:SingleReplicaTopology] or a canonical Single Node topology skip. Otherwise run the serial SNO CI job: /payload-job periodic-ci-openshift-release-master-nightly-4.22-e2e-aws-ovn-single-node-serial
Ipv6 And Disconnected Network Test Compatibility ⚠️ Warning The new serial Ginkgo test creates a Pod with image registry.access.redhat.com/ubi9/ubi-minimal:9.5, which requires a public registry pull and can fail in disconnected CI. Use a cluster-local or mirrored image, or add [Skipped:Disconnected] and run the required serial IPv6 compatibility job.
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: limiting vSphere machine deletion blocking to VMDK-backed volumes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The changed Ginkgo Describe and It titles are static strings; runtime node, namespace, pod, storage-class, and count values appear only in test setup, steps, or assertions.
Microshift Test Compatibility ✅ Passed The new NFS Ginkgo test includes [apigroup:machine.openshift.io], so MicroShift CI skips it before running its Machine API and node-scaling operations.
Topology-Aware Scheduling Compatibility ✅ Passed The changes add no anti-affinity, topology spread, replica, selector, toleration, or PDB constraints. The e2e pod targets only its created machine node, not a topology-specific role.
Ote Binary Stdout Contract ✅ Passed Changed code adds no process-level stdout writes; klog calls are in Reconciler runtime code, and new output-related By calls are inside It. OTE main uses logs.InitLogs().
No-Weak-Crypto ✅ Passed The PR adds volume-attachment classification and NFS test logic only; added lines contain no weak-crypto algorithms, crypto APIs, custom crypto, or secret comparisons.
Container-Privileges ✅ Passed The PR adds no privileged, hostPID, hostNetwork, hostIPC, SYS_ADMIN, allowPrivilegeEscalation, or root security settings; the new Pod has no securityContext.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@jcpowermac

Copy link
Copy Markdown
Contributor Author

/test ?

@jcpowermac

Copy link
Copy Markdown
Contributor Author

/test e2e-vsphere-ovn-techpreview-serial

@jcpowermac

Copy link
Copy Markdown
Contributor Author

/test unit

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/controller/vsphere/reconciler_test.go`:
- Around line 2598-2771: Extend the volumeTypeFilteringTestCases table to cover
nodeHasVolumesAttached conservative fallbacks: add a case with a node-attached
volume but no matching VolumeAttachment object, and a case with a matching
attachment whose Attacher is empty or unrecognized. Configure both cases to
expect deletion blocking with the existing attached-volumes requeue error, and
retain the established machine/node setup and reconcile assertions.

In `@pkg/controller/vsphere/reconciler.go`:
- Around line 581-587: Update the VolumeAttachment attacher classification
around the switch in the reconciler so only explicitly recognized safe
non-vSphere attachers remain in nonVSphereVolumes; route unknown or empty
Attacher values into unknownVolumes, alongside failed lookups. Ensure the
existing unknownVolumes handling and logging are exercised, preserving vSphere
attachers in vsphereVolumes.
- Around line 567-587: The VolumeAttachment lookup in the node volume
classification loop must use the production metadata name for CSI attachments
rather than treating AttachedVolume.Name as the object name. Update the logic
around apiReader.Get and the surrounding reconciliation method to derive the
csi-<sha256(volumeHandle+driver+nodeName)> name, or list and correlate
VolumeAttachment objects by node and attached volume, so non-vSphere CSI volumes
are classified by their real attacher. Update the related tests to use
production-style hashed VolumeAttachment names.

In `@test/e2e/vsphere/machines.go`:
- Around line 282-354: The test must attach an NFS volume to the created
machine’s node before deletion. Extend the flow around testNSName,
nfsStorageClassName, and the machine readiness check to create a PVC and
mounting Pod or DaemonSet using that storage class, ensure it schedules onto
machine.Name’s node, and wait for the corresponding VolumeAttachment or
node.Status.VolumesAttached entry before deleting the machine. Keep the existing
deletion and cluster-size assertions unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c530423b-96ea-445c-9067-22760792a36c

📥 Commits

Reviewing files that changed from the base of the PR and between aaa83f7 and 035aa63.

📒 Files selected for processing (4)
  • ocpbugs-101813.md
  • pkg/controller/vsphere/reconciler.go
  • pkg/controller/vsphere/reconciler_test.go
  • test/e2e/vsphere/machines.go

Comment thread pkg/controller/vsphere/reconciler_test.go
Comment thread pkg/controller/vsphere/reconciler.go
Comment thread pkg/controller/vsphere/reconciler.go Outdated
Comment thread test/e2e/vsphere/machines.go Outdated
@openshift-ci

openshift-ci Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@jcpowermac: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-vsphere-ovn-techpreview-serial 035aa63 link false /test e2e-vsphere-ovn-techpreview-serial

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Aug 4, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@jcpowermac: This pull request references Jira Issue OCPBUGS-101813, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

…olumes

The nodeHasVolumesAttached() check was volume-type-agnostic, blocking machine deletion for any attached volume. This caused indefinite blocking when non-VMDK volumes (NFS, iSCSI, etc.) were attached, since DaemonSet pods with these volumes remain Running and never get evicted.

The VMDK data loss risk only applies to vSphere-backed volumes. This change filters by VolumeAttachment.Spec.Attacher to only block for:

  • csi.vsphere.vmware.com (vSphere CSI)
  • kubernetes.io/vsphere-volume (vSphere in-tree)

Non-vSphere volumes no longer block deletion. Conservative behavior: if VolumeAttachment lookup fails, treat as vSphere-backed and block.

Includes unit tests for volume type filtering and e2e test for NFS volume deletion scenario.

Summary by CodeRabbit

  • Bug Fixes

  • Machine deletion now proceeds when only non-vSphere volumes, such as NFS-backed storage, are attached.

  • Deletion remains safely blocked while vSphere-managed, unidentified, or unresolved volumes may still be attached.

  • Mixed volume attachments are handled correctly, preventing unnecessary deletion delays while protecting active vSphere storage.

  • Tests

  • Added coverage for NFS, vSphere, mixed, unknown, and other CSI volume scenarios.

  • Added end-to-end validation for deleting machines with non-vSphere volumes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
pkg/controller/vsphere/reconciler_test.go (2)

2887-2889: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Use one deadline-bound context for simulator operations.

context.TODO() and context.Background() have no deadline. If AddDevice or reconciler.delete() stalls, this test can wait indefinitely. Create a context.WithTimeout context per subtest and pass it to both operations.

As per path instructions, use context.Context for cancellation and timeouts.

Also applies to: 2913-2918

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/controller/vsphere/reconciler_test.go` around lines 2887 - 2889, Create
one deadline-bound context with context.WithTimeout per subtest in the relevant
test flow, and defer its cancellation. Reuse that context for addDiskToVm and
the reconciler.delete operation, replacing context.TODO()/context.Background()
so both simulator operations terminate when the deadline expires.

Source: Path instructions


2880-2881: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Release simulator resources after each subtest.

Each table entry creates a simulator model and server. The subtest does not call srv.Close() or model.Remove(). Repeated cases can retain listeners and simulator resources until process exit.

Proposed fix
 model, sess, srv := initSimulator(t)
+t.Cleanup(func() {
+	srv.Close()
+	model.Remove()
+})
 simParams, err := getVcenterSimParams(srv, namespace)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/controller/vsphere/reconciler_test.go` around lines 2880 - 2881, Update
the table-driven subtest around initSimulator to release each simulator’s
resources before the subtest exits: ensure srv.Close() and model.Remove() are
called for every entry, including when the subtest fails, using cleanup or
deferred teardown tied to the subtest lifecycle.
test/e2e/vsphere/machines.go (1)

293-299: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Select only attachers that the reconciler treats as non-vSphere.

This test treats openshift-storage.noobaa.io as an NFS provisioner. pkg/controller/vsphere/reconciler.go permits only nfs.csi.k8s.io and csi.nfs.io in its non-vSphere branch. The NooBaa attacher reaches the unknown branch and blocks deletion.

Remove openshift-storage.noobaa.io from this selection, or add the same attacher to the reconciler policy and its unit coverage.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/vsphere/machines.go` around lines 293 - 299, Update the storage
class selection in the test’s storageClasses loop to recognize only provisioners
permitted by the reconciler’s non-vSphere branch: nfs.csi.k8s.io and csi.nfs.io.
Remove openshift-storage.noobaa.io from the condition, unless instead you also
update the reconciler policy and its unit coverage consistently.
♻️ Duplicate comments (1)
pkg/controller/vsphere/reconciler_test.go (1)

2598-2605: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Cover the remaining vSphere attachment paths.

The table does not test VSphereInTreePluginName, although nodeHasVolumesAttached blocks this attacher.

The name-matched fixtures make the first Get succeed. The missing-attachment case only tests an empty list result. Add cases that force Get to return NotFound and List to return a matching attachment, and that force a lookup error. Assert the required deletion and blocking outcomes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/controller/vsphere/reconciler_test.go` around lines 2598 - 2605, Extend
the volumeTypeFilteringTestCases table and its test logic to cover
VSphereInTreePluginName, including name-matched fixtures where Get returns
NotFound, List returns a matching attachment, and lookup returns an error.
Assert that the NotFound/list paths produce the required deletion behavior and
that lookup errors preserve the expected blocking outcome, while keeping
existing attacher cases unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/e2e/vsphere/machines.go`:
- Around line 363-417: Reorder the flow so the Pod creation follows PVC creation
rather than waiting for ClaimBound first, allowing WaitForFirstConsumer
provisioning. Replace the generic node.Status.VolumesAttached length check with
waits that verify pvcName reaches ClaimBound and podName reaches Running on
nodeName; if validating reconciler correlation, additionally locate the PVC’s
VolumeAttachment and confirm its nodeName and expected attacher.
- Around line 372-407: Update the container image in the Pod created by the NFS
test setup around the pod creation call, replacing
registry.redhat.io/ubi8/ubi-minimal:latest with the repository’s configured or
cluster-provided test image, or a fixed digest. Keep the existing container
behavior unchanged while ensuring image resolution is deterministic and does not
depend on an unpinned external tag.

---

Outside diff comments:
In `@pkg/controller/vsphere/reconciler_test.go`:
- Around line 2887-2889: Create one deadline-bound context with
context.WithTimeout per subtest in the relevant test flow, and defer its
cancellation. Reuse that context for addDiskToVm and the reconciler.delete
operation, replacing context.TODO()/context.Background() so both simulator
operations terminate when the deadline expires.
- Around line 2880-2881: Update the table-driven subtest around initSimulator to
release each simulator’s resources before the subtest exits: ensure srv.Close()
and model.Remove() are called for every entry, including when the subtest fails,
using cleanup or deferred teardown tied to the subtest lifecycle.

In `@test/e2e/vsphere/machines.go`:
- Around line 293-299: Update the storage class selection in the test’s
storageClasses loop to recognize only provisioners permitted by the reconciler’s
non-vSphere branch: nfs.csi.k8s.io and csi.nfs.io. Remove
openshift-storage.noobaa.io from the condition, unless instead you also update
the reconciler policy and its unit coverage consistently.

---

Duplicate comments:
In `@pkg/controller/vsphere/reconciler_test.go`:
- Around line 2598-2605: Extend the volumeTypeFilteringTestCases table and its
test logic to cover VSphereInTreePluginName, including name-matched fixtures
where Get returns NotFound, List returns a matching attachment, and lookup
returns an error. Assert that the NotFound/list paths produce the required
deletion behavior and that lookup errors preserve the expected blocking outcome,
while keeping existing attacher cases unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: fc19e4b2-2cdd-432d-b0a9-6f58ccf03c43

📥 Commits

Reviewing files that changed from the base of the PR and between 035aa63 and eedede3.

📒 Files selected for processing (3)
  • pkg/controller/vsphere/reconciler.go
  • pkg/controller/vsphere/reconciler_test.go
  • test/e2e/vsphere/machines.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/controller/vsphere/reconciler.go

Comment thread test/e2e/vsphere/machines.go Outdated
Comment thread test/e2e/vsphere/machines.go Outdated
@jcpowermac
jcpowermac force-pushed the ocpbugs-101813-volume-type-filtering branch from eedede3 to bd366a4 Compare August 4, 2026 12:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/controller/vsphere/reconciler_test.go (1)

2455-2597: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the duplicated test helpers.

vCenterSimConfig, getVcenterSimParams, getMachineWithStatus, getNodeWithConditions, and addDiskToVm are copies of the closures in TestDelete (lines 1935-2059 and 2223-2252). The two copies differ only in instanceUUID. Two copies will drift when the simulator setup changes.

Move these to package-level test helpers in this file, parameterize instanceUUID and nodeName, and call them from both tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/controller/vsphere/reconciler_test.go` around lines 2455 - 2597, Extract
vCenterSimConfig and the helpers getVcenterSimParams, getMachineWithStatus,
getNodeWithConditions, and addDiskToVm from TestDeleteWithVolumeTypeFiltering
and TestDelete into package-level test helpers. Add instanceUUID and nodeName
parameters where needed, preserving each test’s current values and behavior,
then update both tests to call the shared helpers and remove their duplicated
local closures.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/controller/vsphere/reconciler_test.go`:
- Around line 2810-2837: Register the fake client's VolumeAttachment field index
for spec.nodeName in the test setup used by the reconciler cases, including the
index key expected by the fallback List in the missing-attachment scenario.
Ensure the existing test reaches the va == nil path instead of failing because
the field selector index is unavailable.

---

Nitpick comments:
In `@pkg/controller/vsphere/reconciler_test.go`:
- Around line 2455-2597: Extract vCenterSimConfig and the helpers
getVcenterSimParams, getMachineWithStatus, getNodeWithConditions, and
addDiskToVm from TestDeleteWithVolumeTypeFiltering and TestDelete into
package-level test helpers. Add instanceUUID and nodeName parameters where
needed, preserving each test’s current values and behavior, then update both
tests to call the shared helpers and remove their duplicated local closures.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ad47fa12-ce18-438c-b167-f6e793884628

📥 Commits

Reviewing files that changed from the base of the PR and between eedede3 and bd366a4.

📒 Files selected for processing (3)
  • pkg/controller/vsphere/reconciler.go
  • pkg/controller/vsphere/reconciler_test.go
  • test/e2e/vsphere/machines.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/e2e/vsphere/machines.go
  • pkg/controller/vsphere/reconciler.go

Comment thread pkg/controller/vsphere/reconciler_test.go
@jcpowermac
jcpowermac force-pushed the ocpbugs-101813-volume-type-filtering branch 2 times, most recently from 8eb49f2 to 54b5eea Compare August 4, 2026 19:09
@jcpowermac
jcpowermac marked this pull request as ready for review August 5, 2026 12:04
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 5, 2026
…olumes

The nodeHasVolumesAttached() check was volume-type-agnostic, blocking
machine deletion for any attached volume. This caused indefinite blocking
when non-VMDK volumes (NFS, iSCSI, etc.) were attached, since DaemonSet
pods with these volumes remain Running and never get evicted.

The VMDK data loss risk only applies to vSphere-backed volumes. This
change filters by VolumeAttachment.Spec.Attacher to only block deletion
for csi.vsphere.vmware.com (vSphere CSI) and kubernetes.io/vsphere-volume
(vSphere in-tree), whitelisting known-safe non-vSphere CSI attachers
(NFS, iSCSI, Cinder, EBS, GCE PD, Azure Disk) instead of a blanket
default. Empty or unrecognized attachers, and volumes whose
VolumeAttachment lookup fails, are conservatively treated as
vSphere-backed and continue to block deletion.

Adds unit test coverage (TestDeleteWithVolumeTypeFiltering) exercising
NFS, vSphere CSI, vSphere in-tree, mixed, and conservative-blocking
scenarios against a simulated vCenter.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jcpowermac
jcpowermac force-pushed the ocpbugs-101813-volume-type-filtering branch from 54b5eea to 2a06443 Compare August 5, 2026 12:16
@jcpowermac

Copy link
Copy Markdown
Contributor Author

/cc: @gnufied @vr4manta

@jcpowermac

Copy link
Copy Markdown
Contributor Author

/test ?

@jcpowermac

Copy link
Copy Markdown
Contributor Author

/test e2e-vsphere-ovn-multi-vcenter

Comment thread pkg/controller/vsphere/reconciler.go Outdated
return va, nil
}

fieldSelector, err := fields.ParseSelector("spec.nodeName=" + nodeName)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The node selector specified this way will not work for VolumeAttachment objects. For this to work, the k8s API server has to explicitly register spec.nodeName as a selectable. You will have to list all VA objects and filter.

Comment thread pkg/controller/vsphere/reconciler.go Outdated
// csi-<sha256(volumeHandle+driver+nodeName)>).
func (r *Reconciler) getVolumeAttachmentForAttachedVolume(ctx context.Context, volName, nodeName, machineName string) (*storagev1.VolumeAttachment, error) {
va := &storagev1.VolumeAttachment{}
if err := r.apiReader.Get(ctx, apimachinerytypes.NamespacedName{Name: volName}, va); err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will never work. VA names are hashes, not the name in node.VolumesAttached

…t lookup

The previous VolumeAttachment-based approach had two fundamental issues:
- VolumeAttachment names are SHA256 hashes, not the AttachedVolume.Name
- spec.nodeName field selector is not registered for VolumeAttachment

Instead, parse the driver name directly from the UniqueVolumeName format
in node.Status.VolumesAttached (kubernetes.io/csi/<driver>^<handle> for
CSI, kubernetes.io/vsphere-volume/<path> for in-tree). This eliminates
VolumeAttachment API calls entirely while correctly classifying volumes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jcpowermac

Copy link
Copy Markdown
Contributor Author

/test e2e-vsphere-ovn-multi-vcenter

@gnufied

gnufied commented Aug 6, 2026

Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants