VMOwnedVolume- CnsRegisterVolume deferFcdRegistration implementation#4103
Open
deepakkinni wants to merge 9 commits into
Open
VMOwnedVolume- CnsRegisterVolume deferFcdRegistration implementation#4103deepakkinni wants to merge 9 commits into
deepakkinni wants to merge 9 commits into
Conversation
…ce layer, RBAC - Wire go.mod replace directive to deepakkinni/govmomi fork (UnregisterVolumeEx APIs) - Add VMOwnedVolumes FSS constant to WCPFeatureStates and WCPFeatureStatesSupportsLateEnablement - New pkg/apis/cnsoperator/csivolumeinfo/v1alpha1: CsiVolumeInfo types with new schema (vmware-system-csi namespace, cns-volume- prefix, spec.vms[], CSIManaged/VMManaged states) - New csivolumeinfoservice.go: CRUD service layer with AddVolumeProtectionFinalizer/Remove - New config/: CRD YAML manifest + embed wrapper - Register CsiVolumeInfo types in pkg/apis/cnsoperator/register.go - Add csivolumeinfos RBAC to controller and webhook roles in all 4 supervisor manifests - Unit tests (6 passing): deepcopy, CRUD idempotency, finalizer add/remove, not-found
… reconciler - Add UnregisterVolumeEx, QueryPendingUnregisters, AckUnregister to the Manager interface with defaultManager and MockManager implementations. - Create CsiVolumeInfo CR at block-volume provisioning in wcp/controller.go when the VMOwnedVolumes capability is enabled; missing CR is a non-fatal warning so provisioning is never blocked. - Add pkg/syncer/cvi_pv_bind.go: ReconcileCsiVolumeInfoOnPVBind patches the CsiVolumeInfo spec (pvName, pvcName, pvcNamespace) on PV Available→Bound. - Unit tests: manager_unreg_test.go (nil-VC guards, mock success/error paths, type regression guard) and cvi_pv_bind_test.go (no-transition, non-vSphere, missing CR, stale pvName patch, up-to-date no-op, empty volumeHandle). - Fix MockVolumeManager in unittestcommon/types.go and mockVolumeManagerForFullSync in fullsync_test.go to satisfy expanded interface.
Replace raw []cnstypes.CnsUnregisterVolumeResult return type with the []PendingUnregisterRecord wrapper struct in the Manager interface, defaultManager implementation, MockManager, MockVolumeManager, and mockVolumeManagerForFullSync. Also add the PendingUnregisterRecord struct definition before the Manager interface declaration.
Add a new standalone controller that watches CsiVolumeInfo CRs and drives the volume ownership lifecycle based on spec.vms and status.ownership. Two-state machine: UnregisterVolumeEx on first-attach (CSIManaged→VMManaged), CreateVolume re-register on last-detach (VMManaged→CSIManaged). Includes backoff, fault surfacing, brownfield-lazy handling, and table-driven unit tests.
Add RecoverPendingUnregisters to the csivolumeinfo service package. On syncer startup (when VMOwnedVolumes is enabled), query CNS for any PENDING_UNREGISTER rows left from a crash, write disk coordinates to the CsiVolumeInfo spec, advance status to VMManaged, then acknowledge each row. Double-ACK and orphan rows are handled safely. Per-record errors are logged and do not abort recovery for subsequent records.
…e block Add ValidatingAdmissionWebhook guard that rejects PVC deletion when the volume is VM-managed (fail-open on CVI lookup errors). Add snapshot-create rejection in CreateSnapshot when the volume is VM-managed. Both guards are no-ops when VMOwnedVolumes FSS is disabled.
After DeleteVolume succeeds, explicitly delete the CsiVolumeInfo CR for the volume so it does not become an orphan when the PV ownerReference GC hasn't run yet. NotFound is treated as success (idempotent). This covers the permanent-removal path; the normal GC cascade via PV ownerRef still handles the typical case.
- Fix green-signal stall: the unregister reconcile wrote observedGeneration from the generation observed at reconcile entry, but its own diskPath/diskUUID spec write advances metadata.generation. PatchCsiVolumeInfo now returns the post-patch generation and the reconciler and startup recovery record that value, so observedGeneration >= generation can be satisfied. - Treat CnsAlreadyRegisteredFault as success on re-register (add IsCnsAlreadyRegisteredFault helper; check it alongside CnsVolumeAlreadyExistsFault). - Drop the backoff map entry when a CsiVolumeInfo is gone so deleted volumes do not leak entries. - Recovery now writes the full status shape (cleared error + Ready condition), matching the steady-state unregister status. - Retry CsiVolumeInfo patches only on conflict; surface other errors immediately. - PVC-deletion webhook rejection message updated to name the PVC and the action to take. - Remove the invalid integer print column over the spec.vms array. - Move the pending-unregister recovery test alongside the recovery code. - Add the new two-phase unregister methods to the remaining volume.Manager test mocks so all packages compile. - Add PV OwnerRef on CsiVolumeInfo. - Updated webhook Signed-off-by: Deepak Kinni <deepak.kinni@broadcom.com>
Extend CnsRegisterVolume to support VM disk import without FCD registration.
New spec fields: deferFcdRegistration (bool), vmName, vmInstanceUUID, diskUUID.
New status fields: volumeID, pvName.
When deferFcdRegistration=true the controller skips all FCD/CNS operations and
instead derives the volume identity from the PVC UID, creates a PV pre-bound to
that PVC (volumeHandle=PVC UID), and creates a CsiVolumeInfo directly in
VMManaged state with the VM entry and disk metadata. The FCD is registered lazily
at detach time by the existing CsiVolumeInfo register path.
The CRD diskURLPath pattern is broadened to also accept the datastore path form
('[datastore] dir/file.vmdk') used by vm-operator for imported disks.
Includes unit tests covering: happy path, idempotency, missing PVC, FSS disabled,
disk metadata propagation, and no-FCD-call assertion.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deepakkinni The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
PR needs rebase. DetailsInstructions 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
Implements CSI-driver processing of
CnsRegisterVolumeCRs withdeferFcdRegistration=true(VGL-62908 step I.5 — VM disk import, no-FCD path).When vm-operator imports a VM that already has plain VMDKs attached, it backfills
one PVC per disk and creates a
CnsRegisterVolumewithdeferFcdRegistration=true.This PR adds the controller logic to handle that CR without touching vCenter:
volumeID = string(pvc.UID).volumeHandle = volumeID, pre-bound to the PVC.CsiVolumeInfodirectly inVMManagedstate (finalizer + PV ownerRefspec.vmsentry + disk metadata). No FCD, no CNS DB row, no vCenter API call.CnsRegisterVolumeasregistered=truewithvolumeIDandpvNameset in status.
The FCD is registered lazily at detach time by the existing CVI reconciler's
register path (Workflow B, already landed).
Changes:
cnsregistervolume_types.go— new spec fields:deferFcdRegistration,vmName,vmInstanceUUID,diskUUID; new status fields:volumeID,pvName.cnsregistervolume_crd.yaml— new spec/status properties; broadendiskURLPathpattern to also accept the datastore-path form
[ds] dir/file.vmdk.cnsregistervolume_controller.go— wireCsiVolumeInfoService; add FSS-gatedearly branch before
GetVirtualCenterInstance.cnsregistervolume_import.go(new) —reconcileDeferFcdRegistration+ helpers.cnsregistervolume_import_test.go(new) — unit tests (6 cases).Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close that issue when PR gets merged): fixes #Testing done:
Unit tests added in
cnsregistervolume_import_test.go(6 cases):volumeHandle, CVI inVMManaged/Succeededwith
ImportSucceededcondition, CRV statusregistered=truewithvolumeID/pvName.VMOwnedVolumesdisabled: instance error set, no import.diskUUIDanddiskPathcorrectly set in CVI spec.volumeManager.CreateVolumeis never called.make checkpasses clean (staticcheck + golangci-lint zero issues).Special notes for your reviewer:
VMOwnedVolumesFSS; no behaviourchange on clusters where that feature is off.
diskURLPathCRD pattern change is a strict superset — all existingfolder-URL CRVs (
https://host/folder/...) still validate unchanged.StorageClassNameis read from*pvc.Spec.StorageClassNamerather than derivedfrom a storage-policy ID (which would require an FCD QueryVolumeByID). vm-operator
populates it when creating the PVC, and PV↔PVC binding requires the SC to match,
so this is both authoritative and the only available source in the no-FCD path.
zz_generated.deepcopy.gorequired no regeneration: all new fields are scalarsand the existing
*out = *inassignment covers them.Release note: