@@ -207,7 +207,7 @@ func (c *controller) Init(config *cnsconfig.Config, version string) error {
207207
208208 volumeManager , err := cnsvolume .GetManager (ctx , vcenter , operationStore ,
209209 idempotencyHandlingEnabled , false ,
210- false , cnstypes .CnsClusterFlavorWorkload )
210+ false , cnstypes .CnsClusterFlavorWorkload , config . Global . SupervisorID , config . Global . ClusterDistribution )
211211 if err != nil {
212212 return logger .LogNewErrorf (log , "failed to create an instance of volume manager. err=%v" , err )
213213 }
@@ -450,10 +450,9 @@ func (c *controller) ReloadConfiguration(reconnectToVCFromNewConfig bool) error
450450 return logger .LogNewErrorf (log , "failed to reset volume manager. err=%v" , err )
451451 }
452452 c .manager .VcenterConfig = newVCConfig
453-
454453 volumeManager , err := cnsvolume .GetManager (ctx , vcenter , operationStore ,
455454 idempotencyHandlingEnabled , false ,
456- false , cnstypes .CnsClusterFlavorWorkload )
455+ false , cnstypes .CnsClusterFlavorWorkload , cfg . Global . SupervisorID , cfg . Global . ClusterDistribution )
457456 if err != nil {
458457 return logger .LogNewErrorf (log , "failed to create an instance of volume manager. err=%v" , err )
459458 }
@@ -1792,16 +1791,7 @@ func (c *controller) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequ
17921791 return nil , csifault .CSIInvalidArgumentFault , err
17931792 }
17941793 if cnsVolumeType == common .UnknownVolumeType {
1795- cnsVolumeType , err = common .GetCnsVolumeType (ctx , c .manager .VolumeManager , req .VolumeId )
1796- if err != nil {
1797- if err .Error () == common .ErrNotFound .Error () {
1798- // The volume couldn't be found during query, assuming the delete operation as success
1799- return & csi.DeleteVolumeResponse {}, "" , nil
1800- } else {
1801- return nil , csifault .CSIInternalFault , logger .LogNewErrorCodef (log , codes .Internal ,
1802- "failed to determine CNS volume type for volume: %q. Error: %+v" , req .VolumeId , err )
1803- }
1804- }
1794+ cnsVolumeType = common .GetCnsVolumeType (ctx , req .VolumeId )
18051795 volumeType = convertCnsVolumeType (ctx , cnsVolumeType )
18061796 }
18071797 // Check if the volume contains CNS snapshots only for block volumes.
@@ -2503,66 +2493,21 @@ func (c *controller) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshot
25032493 }
25042494 volumeID := req .GetSourceVolumeId ()
25052495 volumeType = prometheus .PrometheusBlockVolumeType
2506- // Query capacity in MB for block volume snapshot
2507- volumeIds := []cnstypes.CnsVolumeId {{Id : volumeID }}
2508- cnsVolumeDetailsMap , err := utils .QueryVolumeDetailsUtil (ctx , c .manager .VolumeManager , volumeIds )
2509- if err != nil {
2510- return nil , err
2511- }
2512- if _ , ok := cnsVolumeDetailsMap [volumeID ]; ! ok {
2513- return nil , logger .LogNewErrorCodef (log , codes .Internal ,
2514- "cns query volume did not return the volume: %s" , volumeID )
2515- }
2516- snapshotSizeInMB := cnsVolumeDetailsMap [volumeID ].SizeInMB
25172496
2518- if cnsVolumeDetailsMap [volumeID ].VolumeType != common .BlockVolumeType {
2497+ cnsvolumeType := common .GetCnsVolumeType (ctx , volumeID )
2498+ if cnsvolumeType != common .BlockVolumeType {
25192499 return nil , logger .LogNewErrorCodef (log , codes .FailedPrecondition ,
2520- "queried volume doesn't have the expected volume type. Expected VolumeType: %v. " +
2521- "Queried VolumeType: %v" , volumeType , cnsVolumeDetailsMap [volumeID ].VolumeType )
2522- }
2523-
2524- // Extract namespace from request parameters
2525- volumeSnapshotNamespace := req .Parameters [common .VolumeSnapshotNamespaceKey ]
2526- if volumeSnapshotNamespace == "" {
2527- return nil , logger .LogNewErrorCodef (log , codes .Internal ,
2528- "volumesnapshot namespace is not set in the request parameters" )
2529- }
2530-
2531- // Get snapshot limit from namespace ConfigMap
2532- snapshotLimit , err := getSnapshotLimitForNamespace (ctx , volumeSnapshotNamespace )
2533- if err != nil {
2534- return nil , logger .LogNewErrorCodef (log , codes .Internal ,
2535- "failed to get snapshot limit for namespace %q: %v" , volumeSnapshotNamespace , err )
2500+ "Expected VolumeType: %v. " +
2501+ "Observed VolumeType: %v" , volumeType , cnsvolumeType )
25362502 }
2537- log .Infof ("Snapshot limit for namespace %q is set to %d" , volumeSnapshotNamespace , snapshotLimit )
2538-
2539- // Acquire lock for this volume to serialize snapshot operations
2540- c .acquireSnapshotLock (ctx , volumeID )
2541- defer c .releaseSnapshotLock (ctx , volumeID )
2542-
2543- // Query existing snapshots for this volume
2544- snapshotList , _ , err := common .QueryVolumeSnapshotsByVolumeID (ctx , c .manager .VolumeManager , volumeID ,
2545- common .QuerySnapshotLimit )
2546- if err != nil {
2547- return nil , logger .LogNewErrorCodef (log , codes .Internal ,
2548- "failed to query snapshots for volume %q: %v" , volumeID , err )
2549- }
2550-
2551- // Check if the limit is exceeded
2552- currentSnapshotCount := len (snapshotList )
2553- if currentSnapshotCount >= snapshotLimit {
2554- return nil , logger .LogNewErrorCodef (log , codes .FailedPrecondition ,
2555- "the number of snapshots (%d) on the source volume %s has reached or exceeded " +
2556- "the configured maximum (%d) for namespace %s" ,
2557- currentSnapshotCount , volumeID , snapshotLimit , volumeSnapshotNamespace )
2558- }
2559- log .Infof ("Current snapshot count for volume %q is %d, within limit of %d" ,
2560- volumeID , currentSnapshotCount , snapshotLimit )
2503+ // TODO: We may need to add logic to check the limit of max number of snapshots by using
2504+ // GlobalMaxSnapshotsPerBlockVolume etc. variables in the future.
25612505
25622506 // the returned snapshotID below is a combination of CNS VolumeID and CNS SnapshotID concatenated by the "+"
25632507 // sign. That is, a string of "<UUID>+<UUID>". Because, all other CNS snapshot APIs still require both
25642508 // VolumeID and SnapshotID as the input, while corresponding snapshot APIs in upstream CSI require SnapshotID.
25652509 // So, we need to bridge the gap in vSphere CSI driver and return a combined SnapshotID to CSI Snapshotter.
2510+ var err error
25662511 var snapshotID string
25672512 var cnsSnapshotInfo * cnsvolume.CnsSnapshotInfo
25682513 var cnsVolumeInfo * cnsvolumeinfov1alpha1.CNSVolumeInfo
@@ -2618,6 +2563,17 @@ func (c *controller) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshot
26182563 "failed to create snapshot on volume %q with error: %v" , volumeID , err )
26192564 }
26202565 }
2566+ // Query capacity in MB for block volume snapshot
2567+ volumeIds := []cnstypes.CnsVolumeId {{Id : volumeID }}
2568+ cnsVolumeDetailsMap , err := utils .QueryVolumeDetailsUtil (ctx , c .manager .VolumeManager , volumeIds )
2569+ if err != nil {
2570+ return nil , err
2571+ }
2572+ if _ , ok := cnsVolumeDetailsMap [volumeID ]; ! ok {
2573+ return nil , logger .LogNewErrorCodef (log , codes .Internal ,
2574+ "cns query volume did not return the volume: %s" , volumeID )
2575+ }
2576+ snapshotSizeInMB := cnsVolumeDetailsMap [volumeID ].SizeInMB
26212577 snapshotCreateTimeInProto := timestamppb .New (cnsSnapshotInfo .SnapshotLatestOperationCompleteTime )
26222578 createSnapshotResponse := & csi.CreateSnapshotResponse {
26232579 Snapshot : & csi.Snapshot {
@@ -2635,6 +2591,7 @@ func (c *controller) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshot
26352591 cnsSnapshotInfo .SnapshotLatestOperationCompleteTime , createSnapshotResponse )
26362592
26372593 volumeSnapshotName := req .Parameters [common .VolumeSnapshotNameKey ]
2594+ volumeSnapshotNamespace := req .Parameters [common .VolumeSnapshotNamespaceKey ]
26382595 log .Infof ("Attempting to annotate volumesnapshot %s/%s with annotation %s:%s" ,
26392596 volumeSnapshotNamespace , volumeSnapshotName , common .VolumeSnapshotInfoKey , snapshotID )
26402597 annotated , err := commonco .ContainerOrchestratorUtility .AnnotateVolumeSnapshot (ctx , volumeSnapshotName ,
@@ -2808,11 +2765,7 @@ func (c *controller) ControllerExpandVolume(ctx context.Context, req *csi.Contro
28082765 // Later we may need to define different csi faults.
28092766 // Check if the volume contains CNS snapshots only for block volumes.
28102767 if cnsVolumeType == common .UnknownVolumeType {
2811- cnsVolumeType , err = common .GetCnsVolumeType (ctx , c .manager .VolumeManager , req .VolumeId )
2812- if err != nil {
2813- return nil , csifault .CSIInternalFault , logger .LogNewErrorCodef (log , codes .Internal ,
2814- "failed to determine CNS volume type for volume: %q. Error: %+v" , req .VolumeId , err )
2815- }
2768+ cnsVolumeType = common .GetCnsVolumeType (ctx , req .VolumeId )
28162769 volumeType = convertCnsVolumeType (ctx , cnsVolumeType )
28172770 }
28182771 if cnsVolumeType == common .BlockVolumeType &&
0 commit comments