Skip to content

Conversation

@skogta
Copy link
Contributor

@skogta skogta commented Nov 28, 2025

What this PR does / why we need it:

Update CnsNodeVMBatchAttachment reconciliation to only attach those volumes which are not already attached to the VM.

It is also important to ensure that the CR's status reflects the VM on the VC. So if a VM has a volume attached on the VC but the CR's status does not reflect the same, then that volume must be re-attached again.

Testing done:
Created a batchattach CR with 1 volume:

{"level":"info","time":"2025-11-28T22:40:28.986867198Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:660","msg":"List of attached FCDs map[] to VM 115fb267-e20b-4b6e-ada7-ba0855c1b6f2","TraceId":"28126c85-acfd-49a5-b986-deb941571e79"}
{"level":"info","time":"2025-11-28T22:40:28.987411281Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:137","msg":"Obtained volumes to detach map[] for instance test-lim-batch","TraceId":"28126c85-acfd-49a5-b986-deb941571e79"}
{"level":"info","time":"2025-11-28T22:40:28.98746226Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:705","msg":"Volumes to be detached map[] for instance test-lim-batch","TraceId":"28126c85-acfd-49a5-b986-deb941571e79"}
{"level":"info","time":"2025-11-28T22:40:28.987518234Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:176","msg":"PVC my-pvc-1 not attached to VM. Adding it to volumesToAttach list","TraceId":"28126c85-acfd-49a5-b986-deb941571e79"}
{"level":"info","time":"2025-11-28T22:40:28.987793767Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:200","msg":"Obtained volumes to attach map[my-pvc-1:2c4b4fcf-1423-4247-853f-31c5e6855bd2] for instance test-lim-batch","TraceId":"28126c85-acfd-49a5-b986-deb941571e79"}
{"level":"info","time":"2025-11-28T22:40:31.543275194Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:525","msg":"Successfully batch attached all volumes","TraceId":"28126c85-acfd-49a5-b986-deb941571e79"}
{"level":"info","time":"2025-11-28T22:40:31.54349736Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:816","msg":"Acquired lock for PVC test/my-pvc-1","TraceId":"28126c85-acfd-49a5-b986-deb941571e79"}

Added 1 more volume and observed only 1 volume got attached:

{"level":"info","time":"2025-11-28T22:43:32.658262766Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:660","msg":"List of attached FCDs map[2c4b4fcf-1423-4247-853f-31c5e6855bd2:{ControllerKey:1000 UnitNumber:3 DiskMode:independent_persistent SharingMode:sharingMultiWriter}] to VM 115fb267-e20b-4b6e-ada7-ba0855c1b6f2","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:32.658556019Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:137","msg":"Obtained volumes to detach map[] for instance test-lim-batch","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:32.658594823Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:705","msg":"Volumes to be detached map[] for instance test-lim-batch","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:32.658603112Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:176","msg":"PVC my-pvc-2 not attached to VM. Adding it to volumesToAttach list","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:32.658785048Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:200","msg":"Obtained volumes to attach map[my-pvc-2:2c3186ce-41b5-4a16-98a3-59a855e35ca4] for instance test-lim-batch","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:32.658934673Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:579","msg":"Constructing batch attach request for instance test-lim-batch","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:32.659033456Z","caller":"volume/manager.go:3562","msg":"Starting batch attach for VM 115fb267-e20b-4b6e-ada7-ba0855c1b6f2","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:32.66624854Z","caller":"volume/manager.go:3546","msg":"Constucted CnsVolumeAttachDetachSpec for VM 115fb267-e20b-4b6e-ada7-ba0855c1b6f2","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:35.569128315Z","caller":"volume/manager.go:3515","msg":"Constructed batch attach result for volume 2c3186ce-41b5-4a16-98a3-59a855e35ca4 with success","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:35.569188055Z","caller":"volume/manager.go:3642","msg":"BatchAttach: all volumes attached successfully with opID 3a3ddf8c","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}
{"level":"info","time":"2025-11-28T22:43:35.569229348Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:525","msg":"Successfully batch attached all volumes","TraceId":"e8a4e4d1-9958-4017-a135-fc829c6bc2c1"}

Detached 1 volume and observed no volumes were attached:

{"level":"info","time":"2025-11-28T22:45:43.039004032Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:660","msg":"List of attached FCDs map[2c3186ce-41b5-4a16-98a3-59a855e35ca4:{ControllerKey:1000 UnitNumber:6 DiskMode:independent_persistent SharingMode:sharingMultiWriter} 2c4b4fcf-1423-4247-853f-31c5e6855bd2:{ControllerKey:1000 UnitNumber:3 DiskMode:independent_persistent SharingMode:sharingMultiWriter}] to VM 115fb267-e20b-4b6e-ada7-ba0855c1b6f2","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:43.039051712Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:792","msg":"Annotation with prefix cns.vmware.com/usedby-vm- found on PVC my-pvc-1","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:43.039065541Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:137","msg":"Obtained volumes to detach map[my-pvc-1:2c4b4fcf-1423-4247-853f-31c5e6855bd2] for instance test-lim-batch","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:43.039086119Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:366","msg":"Updating status name entry to disk-1:detaching for detaching PVC my-pvc-1","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:43.039100737Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:705","msg":"Volumes to be detached map[my-pvc-1:2c4b4fcf-1423-4247-853f-31c5e6855bd2] for instance test-lim-batch","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:43.039122457Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:200","msg":"Obtained volumes to attach map[] for instance test-lim-batch","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:43.03913207Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:446","msg":"Detach call started for PVC my-pvc-1 with volumeID 2c4b4fcf-1423-4247-853f-31c5e6855bd2 in namespace test for instance test-lim-batch","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:44.671472825Z","caller":"volume/manager.go:1263","msg":"DetachVolume: volumeID: \"2c4b4fcf-1423-4247-853f-31c5e6855bd2\", vm: \"VirtualMachine:vm-1022 [VirtualCenterHost: lvn-dvm-10-162-75-216.dvm.lvn.broadcom.net, UUID: 115fb267-e20b-4b6e-ada7-ba0855c1b6f2, Datacenter: Datacenter [Datacenter: Datacenter:datacenter-3, VirtualCenterHost: lvn-dvm-10-162-75-216.dvm.lvn.broadcom.net]]\", opId: \"3a3ddff8\"","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:44.671787536Z","caller":"volume/manager.go:1313","msg":"DetachVolume: Volume detached successfully. volumeID: \"2c4b4fcf-1423-4247-853f-31c5e6855bd2\", vm: \"VirtualMachine:vm-1022 [VirtualCenterHost: lvn-dvm-10-162-75-216.dvm.lvn.broadcom.net, UUID: 115fb267-e20b-4b6e-ada7-ba0855c1b6f2, Datacenter: Datacenter [Datacenter: Datacenter:datacenter-3, VirtualCenterHost: lvn-dvm-10-162-75-216.dvm.lvn.broadcom.net]]\", opId: \"3a3ddff8\"","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:44.814442681Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:401","msg":"Successfully detached all volumes map[my-pvc-1:2c4b4fcf-1423-4247-853f-31c5e6855bd2]","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:44.814453821Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:508","msg":"No volumes to attach to VM \"115fb267-e20b-4b6e-ada7-ba0855c1b6f2\"","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}
{"level":"info","time":"2025-11-28T22:45:44.840262434Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:583","msg":"ReconcileCnsNodeVMBatchAttachment: Successfully processed instance test/test-lim-batch in namespace \"test/test-lim-batch\".","TraceId":"5e45a9ef-8418-4cd2-be70-676c5d1adee3"}

Deleted the instance, observed that volume was detached and the CR was also deleted:

{"level":"info","time":"2025-11-28T22:48:01.868168074Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:631","msg":"Obtained VM object for VM 115fb267-e20b-4b6e-ada7-ba0855c1b6f2 from VC","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:01.869280439Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:350","msg":"Deletion timestamp observed on instance test/test-lim-batch. Detaching all volumes.","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:01.869369566Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:446","msg":"Detach call started for PVC my-pvc-2 with volumeID 2c3186ce-41b5-4a16-98a3-59a855e35ca4 in namespace test for instance test-lim-batch","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.294603911Z","caller":"volume/manager.go:1263","msg":"DetachVolume: volumeID: \"2c3186ce-41b5-4a16-98a3-59a855e35ca4\", vm: \"VirtualMachine:vm-1022 [VirtualCenterHost: lvn-dvm-10-162-75-216.dvm.lvn.broadcom.net, UUID: 115fb267-e20b-4b6e-ada7-ba0855c1b6f2, Datacenter: Datacenter [Datacenter: Datacenter:datacenter-3, VirtualCenterHost: lvn-dvm-10-162-75-216.dvm.lvn.broadcom.net]]\", opId: \"3a3de04e\"","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.294637835Z","caller":"volume/manager.go:1313","msg":"DetachVolume: Volume detached successfully. volumeID: \"2c3186ce-41b5-4a16-98a3-59a855e35ca4\", vm: \"VirtualMachine:vm-1022 [VirtualCenterHost: lvn-dvm-10-162-75-216.dvm.lvn.broadcom.net, UUID: 115fb267-e20b-4b6e-ada7-ba0855c1b6f2, Datacenter: Datacenter [Datacenter: Datacenter:datacenter-3, VirtualCenterHost: lvn-dvm-10-162-75-216.dvm.lvn.broadcom.net]]\", opId: \"3a3de04e\"","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.294718056Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:874","msg":"Acquired lock for PVC test/my-pvc-2","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.294892126Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:741","msg":"Removing annotation cns.vmware.com/usedby-vm-115fb267-e20b-4b6e-ada7-ba0855c1b6f2 from PVC my-pvc-2","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.294961965Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:763","msg":"Patching PVC my-pvc-2 with updated annotation","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.358776358Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:905","msg":"Successfully updated annotations on PVC my-pvc-2 for VM 115fb267-e20b-4b6e-ada7-ba0855c1b6f2","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.364433083Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:797","msg":"PVC my-pvc-2 does not contain any annotations with prefix cns.vmware.com/usedby-vm-","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.364487925Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:921","msg":"VM 115fb267-e20b-4b6e-ada7-ba0855c1b6f2 was the last attached VM for the PVC my-pvc-2. Finalizer cns.vmware.com/pvc-protection can be safely removed fromt the PVC","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.364500372Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:934","msg":"Removing cns.vmware.com/pvc-protection finalizer from PVC: my-pvc-2 on namespace: test","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.410030233Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:947","msg":"Successfully removed finalizer cns.vmware.com/pvc-protection from PVC my-pvc-2","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.410533664Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:877","msg":"Released lock for PVC test/my-pvc-2","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.410739838Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:494","msg":"Successfully detached volume my-pvc-2 from VM 115fb267-e20b-4b6e-ada7-ba0855c1b6f2","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.410829757Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_controller.go:470","msg":"Detach call ended for PVC my-pvc-2 in namespace test for instance test-lim-batch","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}
{"level":"info","time":"2025-11-28T22:48:04.411138475Z","caller":"cnsnodevmbatchattachment/cnsnodevmbatchattachment_helper.go:74","msg":"Removing \"cns.vmware.com\" finalizer from CnsNodeVMBatchAttachment instance with name: \"test-lim-batch\" on namespace: \"test\"","TraceId":"bef8422c-d865-4bab-b5ed-8f9889f18f8d"}

WCP precheckin: https://jenkins-vcf-csifvt.devops.broadcom.net/job/wcp-instapp-e2e-pre-checkin/669/
VKS precheckin: https://jenkins-vcf-csifvt.devops.broadcom.net/job/vks-instapp-e2e-pre-checkin/619/

@skogta skogta marked this pull request as draft November 28, 2025 19:36
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 28, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 28, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @skogta. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 28, 2025
@skogta skogta force-pushed the topic/skogta/attachLimitesVolumes branch 2 times, most recently from ef83dbd to aae08b0 Compare November 28, 2025 21:44
@skogta skogta marked this pull request as ready for review November 28, 2025 22:51
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 28, 2025
@skogta skogta force-pushed the topic/skogta/attachLimitesVolumes branch 2 times, most recently from 791a5e7 to e090c56 Compare November 28, 2025 23:11
@skogta skogta force-pushed the topic/skogta/attachLimitesVolumes branch from e090c56 to d846a3b Compare November 28, 2025 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants