@@ -194,7 +194,7 @@ func (c *controller) Init(config *cnsconfig.Config, version string) error {
194194
195195 volumeManager , err := cnsvolume .GetManager (ctx , vcenter , operationStore ,
196196 idempotencyHandlingEnabled , false ,
197- false , cnstypes .CnsClusterFlavorWorkload )
197+ false , cnstypes .CnsClusterFlavorWorkload , config . Global . SupervisorID , config . Global . ClusterDistribution )
198198 if err != nil {
199199 return logger .LogNewErrorf (log , "failed to create an instance of volume manager. err=%v" , err )
200200 }
@@ -431,10 +431,9 @@ func (c *controller) ReloadConfiguration(reconnectToVCFromNewConfig bool) error
431431 return logger .LogNewErrorf (log , "failed to reset volume manager. err=%v" , err )
432432 }
433433 c .manager .VcenterConfig = newVCConfig
434-
435434 volumeManager , err := cnsvolume .GetManager (ctx , vcenter , operationStore ,
436435 idempotencyHandlingEnabled , false ,
437- false , cnstypes .CnsClusterFlavorWorkload )
436+ false , cnstypes .CnsClusterFlavorWorkload , cfg . Global . SupervisorID , cfg . Global . ClusterDistribution )
438437 if err != nil {
439438 return logger .LogNewErrorf (log , "failed to create an instance of volume manager. err=%v" , err )
440439 }
@@ -1722,16 +1721,7 @@ func (c *controller) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequ
17221721 return nil , csifault .CSIInvalidArgumentFault , err
17231722 }
17241723 if cnsVolumeType == common .UnknownVolumeType {
1725- cnsVolumeType , err = common .GetCnsVolumeType (ctx , c .manager .VolumeManager , req .VolumeId )
1726- if err != nil {
1727- if err .Error () == common .ErrNotFound .Error () {
1728- // The volume couldn't be found during query, assuming the delete operation as success
1729- return & csi.DeleteVolumeResponse {}, "" , nil
1730- } else {
1731- return nil , csifault .CSIInternalFault , logger .LogNewErrorCodef (log , codes .Internal ,
1732- "failed to determine CNS volume type for volume: %q. Error: %+v" , req .VolumeId , err )
1733- }
1734- }
1724+ cnsVolumeType = common .GetCnsVolumeType (ctx , req .VolumeId )
17351725 volumeType = convertCnsVolumeType (ctx , cnsVolumeType )
17361726 }
17371727 // Check if the volume contains CNS snapshots only for block volumes.
@@ -2433,31 +2423,21 @@ func (c *controller) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshot
24332423 }
24342424 volumeID := req .GetSourceVolumeId ()
24352425 volumeType = prometheus .PrometheusBlockVolumeType
2436- // Query capacity in MB for block volume snapshot
2437- volumeIds := []cnstypes.CnsVolumeId {{Id : volumeID }}
2438- cnsVolumeDetailsMap , err := utils .QueryVolumeDetailsUtil (ctx , c .manager .VolumeManager , volumeIds )
2439- if err != nil {
2440- return nil , err
2441- }
2442- if _ , ok := cnsVolumeDetailsMap [volumeID ]; ! ok {
2443- return nil , logger .LogNewErrorCodef (log , codes .Internal ,
2444- "cns query volume did not return the volume: %s" , volumeID )
2445- }
2446- snapshotSizeInMB := cnsVolumeDetailsMap [volumeID ].SizeInMB
24472426
2448- if cnsVolumeDetailsMap [volumeID ].VolumeType != common .BlockVolumeType {
2427+ cnsvolumeType := common .GetCnsVolumeType (ctx , volumeID )
2428+ if cnsvolumeType != common .BlockVolumeType {
24492429 return nil , logger .LogNewErrorCodef (log , codes .FailedPrecondition ,
2450- "queried volume doesn't have the expected volume type. Expected VolumeType: %v. " +
2451- "Queried VolumeType: %v" , volumeType , cnsVolumeDetailsMap [ volumeID ]. VolumeType )
2430+ "Expected VolumeType: %v. " +
2431+ "Observed VolumeType: %v" , volumeType , cnsvolumeType )
24522432 }
2453-
24542433 // TODO: We may need to add logic to check the limit of max number of snapshots by using
24552434 // GlobalMaxSnapshotsPerBlockVolume etc. variables in the future.
24562435
24572436 // the returned snapshotID below is a combination of CNS VolumeID and CNS SnapshotID concatenated by the "+"
24582437 // sign. That is, a string of "<UUID>+<UUID>". Because, all other CNS snapshot APIs still require both
24592438 // VolumeID and SnapshotID as the input, while corresponding snapshot APIs in upstream CSI require SnapshotID.
24602439 // So, we need to bridge the gap in vSphere CSI driver and return a combined SnapshotID to CSI Snapshotter.
2440+ var err error
24612441 var snapshotID string
24622442 var cnsSnapshotInfo * cnsvolume.CnsSnapshotInfo
24632443 var cnsVolumeInfo * cnsvolumeinfov1alpha1.CNSVolumeInfo
@@ -2513,6 +2493,17 @@ func (c *controller) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshot
25132493 "failed to create snapshot on volume %q with error: %v" , volumeID , err )
25142494 }
25152495 }
2496+ // Query capacity in MB for block volume snapshot
2497+ volumeIds := []cnstypes.CnsVolumeId {{Id : volumeID }}
2498+ cnsVolumeDetailsMap , err := utils .QueryVolumeDetailsUtil (ctx , c .manager .VolumeManager , volumeIds )
2499+ if err != nil {
2500+ return nil , err
2501+ }
2502+ if _ , ok := cnsVolumeDetailsMap [volumeID ]; ! ok {
2503+ return nil , logger .LogNewErrorCodef (log , codes .Internal ,
2504+ "cns query volume did not return the volume: %s" , volumeID )
2505+ }
2506+ snapshotSizeInMB := cnsVolumeDetailsMap [volumeID ].SizeInMB
25162507 snapshotCreateTimeInProto := timestamppb .New (cnsSnapshotInfo .SnapshotLatestOperationCompleteTime )
25172508 createSnapshotResponse := & csi.CreateSnapshotResponse {
25182509 Snapshot : & csi.Snapshot {
@@ -2704,11 +2695,7 @@ func (c *controller) ControllerExpandVolume(ctx context.Context, req *csi.Contro
27042695 // Later we may need to define different csi faults.
27052696 // Check if the volume contains CNS snapshots only for block volumes.
27062697 if cnsVolumeType == common .UnknownVolumeType {
2707- cnsVolumeType , err = common .GetCnsVolumeType (ctx , c .manager .VolumeManager , req .VolumeId )
2708- if err != nil {
2709- return nil , csifault .CSIInternalFault , logger .LogNewErrorCodef (log , codes .Internal ,
2710- "failed to determine CNS volume type for volume: %q. Error: %+v" , req .VolumeId , err )
2711- }
2698+ cnsVolumeType = common .GetCnsVolumeType (ctx , req .VolumeId )
27122699 volumeType = convertCnsVolumeType (ctx , cnsVolumeType )
27132700 }
27142701 if cnsVolumeType == common .BlockVolumeType &&
0 commit comments