@@ -152,7 +152,7 @@ func getVolumesToDetachForVmFromVC(ctx context.Context,
152
152
153
153
pvcsToDetach := make (map [string ]string )
154
154
// Get all PVCs and their corresponding volumeID mapping from instance spec.
155
- volumeIdsInSpec , volumeNamesInSpec , err := getVolumeNameVolumeIdMapsInSpec (ctx , instance )
155
+ volumeIdsInSpec , volumeNamesInSpec , err := getVolumeNameVolumeIdMapsInSpec (ctx , instance , client )
156
156
if err != nil {
157
157
log .Errorf ("failed to get PVCs in spec. Err: %s" , err )
158
158
return pvcsToDetach , err
@@ -248,7 +248,8 @@ func deleteVolumeFromStatus(pvc string, instance *v1alpha1.CnsNodeVmBatchAttachm
248
248
// 1. volumeID to PVC name
249
249
// 2. VolumeName to PVC name
250
250
func getVolumeNameVolumeIdMapsInSpec (ctx context.Context ,
251
- instance * v1alpha1.CnsNodeVmBatchAttachment ) (volumeIdsInSpec map [string ]string ,
251
+ instance * v1alpha1.CnsNodeVmBatchAttachment ,
252
+ client client.Client ) (volumeIdsInSpec map [string ]string ,
252
253
volumeNamesInSpec map [string ]string , err error ) {
253
254
log := logger .GetLogger (ctx )
254
255
@@ -270,12 +271,13 @@ func getVolumeNameVolumeIdMapsInSpec(ctx context.Context,
270
271
}
271
272
272
273
// getPvcsInSpec returns map of PVCs and their volumeIDs.
273
- func getPvcsInSpec (instance * v1alpha1.CnsNodeVmBatchAttachment ) (map [string ]string , error ) {
274
+ func getPvcsInSpec (ctx context. Context , instance * v1alpha1.CnsNodeVmBatchAttachment , client client. Client ) (map [string ]string , error ) {
274
275
pvcsInSpec := make (map [string ]string )
275
276
for _ , volume := range instance .Spec .Volumes {
276
277
namespacedPvcName := getNamespacedPvcName (instance .Namespace , volume .PersistentVolumeClaim .ClaimName )
277
278
volumeId , ok := commonco .ContainerOrchestratorUtility .GetVolumeIDFromPVCName (namespacedPvcName )
278
279
if ! ok {
280
+
279
281
return pvcsInSpec , fmt .Errorf ("failed to find volumeID for PVC %s" , volume .PersistentVolumeClaim .ClaimName )
280
282
}
281
283
pvcsInSpec [volume .PersistentVolumeClaim .ClaimName ] = volumeId
@@ -461,7 +463,7 @@ func getVolumesToDetach(ctx context.Context, instance *v1alpha1.CnsNodeVmBatchAt
461
463
462
464
if instance .DeletionTimestamp != nil {
463
465
log .Debugf ("Instance %s is being deleted, adding all volumes in spec to volumesToDetach list." , instance .Name )
464
- volumesToDetach , err := getPvcsInSpec (instance )
466
+ volumesToDetach , err := getPvcsInSpec (ctx , instance , client )
465
467
if err != nil {
466
468
log .Errorf ("failed to get volumes to detach from instance spec. Err: %s" , err )
467
469
return volumesToDetach , err
0 commit comments