@@ -362,13 +362,14 @@ func constructBatchAttachRequest(ctx context.Context,
362
362
UnitNumber : volume .PersistentVolumeClaim .UnitNumber ,
363
363
}
364
364
// Validate each attach request before proceeding.
365
- err := validateBatchAttachRequest (ctx , currentBatchAttachRequest , instance .Namespace , pvcName )
365
+ updateBatchAttachRequest , err := validateBatchAttachRequest (ctx ,
366
+ currentBatchAttachRequest , instance .Namespace , pvcName )
366
367
if err != nil {
367
368
log .Errorf ("failed to validate attach request for PVC %s in namespace %s. Err: %s" ,
368
369
pvcName , instance .Namespace , err )
369
370
return pvcsInSpec , volumeIdsInSpec , batchAttachRequest , err
370
371
}
371
- batchAttachRequest = append (batchAttachRequest , currentBatchAttachRequest )
372
+ batchAttachRequest = append (batchAttachRequest , updateBatchAttachRequest )
372
373
}
373
374
return pvcsInSpec , volumeIdsInSpec , batchAttachRequest , nil
374
375
}
@@ -378,7 +379,7 @@ func constructBatchAttachRequest(ctx context.Context,
378
379
// RWX accessMode -> ControllerKey and UnitNumber are required, DiskMode must be IndependentPersistent.
379
380
// RWO accessMode -> DiskMode must not be IndependentPersistent, SharingMode must not be SharingMultiWriter.
380
381
func validateBatchAttachRequest (ctx context.Context ,
381
- batchAttachRequest volumes.BatchAttachRequest , namespace string , pvcName string ) error {
382
+ batchAttachRequest volumes.BatchAttachRequest , namespace string , pvcName string ) (volumes. BatchAttachRequest , error ) {
382
383
log := logger .GetLogger (ctx )
383
384
384
385
log .Infof ("Verifying if PVC %s has correct input parameters for batch attach" , pvcName )
@@ -387,46 +388,53 @@ func validateBatchAttachRequest(ctx context.Context,
387
388
pvc , err := commonco .ContainerOrchestratorUtility .GetPvcObjectByName (ctx , pvcName , namespace )
388
389
if err != nil {
389
390
log .Errorf ("failed to get PVC object for PVC %s. Err: %s" , pvcName , err )
390
- return err
391
+ return batchAttachRequest , err
391
392
}
392
393
393
394
for _ , accessMode := range pvc .Spec .AccessModes {
394
395
// RWX accessMode -> ControllerKey and UnitNumber are required, DiskMode must be IndependentPersistent.
395
396
if accessMode == v1 .ReadWriteMany || accessMode == v1 .ReadOnlyMany {
397
+ if batchAttachRequest .DiskMode == "" {
398
+ batchAttachRequest .DiskMode = string (v1alpha1 .IndependentPersistent )
399
+ }
396
400
if batchAttachRequest .DiskMode != string (v1alpha1 .IndependentPersistent ) {
397
- return fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
401
+ return batchAttachRequest , fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
398
402
"DiskMode cannot be %s" , pvcName , namespace , accessMode , batchAttachRequest .DiskMode )
399
403
}
400
404
if batchAttachRequest .ControllerKey == "" {
401
- return fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
405
+ return batchAttachRequest , fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
402
406
"ControllerKey cannot be empty" , pvcName , namespace , accessMode )
403
407
}
404
408
if batchAttachRequest .UnitNumber == "" {
405
- return fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
409
+ return batchAttachRequest , fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
406
410
" UnitNumber cannot be empty" , pvcName , namespace , accessMode )
407
411
}
412
+ if batchAttachRequest .SharingMode == "" {
413
+ return batchAttachRequest , fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
414
+ " SharingMode cannot be empty" , pvcName , namespace , accessMode )
415
+ }
408
416
}
409
417
410
- // RWO accessMode -> DiskMode must NOT be IndependentPersistent, SharingMode must not be SharingMultiWriter .
418
+ // RWO accessMode -> DiskMode, SharingMode and ControllerNumber and Unit Number must be empty .
411
419
if accessMode == v1 .ReadWriteOnce {
412
- if batchAttachRequest .DiskMode != string ( v1alpha1 . Persistent ) && batchAttachRequest . DiskMode != "" {
413
- return fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
420
+ if batchAttachRequest .DiskMode != "" {
421
+ return batchAttachRequest , fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
414
422
"DiskMode cannot be %s" , pvcName , namespace , accessMode , batchAttachRequest .DiskMode )
415
423
}
416
- if batchAttachRequest .SharingMode != string ( v1alpha1 . SharingNone ) && batchAttachRequest . SharingMode != "" {
417
- return fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
424
+ if batchAttachRequest .SharingMode != "" {
425
+ return batchAttachRequest , fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
418
426
"SharingMode cannot be %s" , pvcName , namespace , accessMode , batchAttachRequest .SharingMode )
419
427
}
420
- if batchAttachRequest .ControllerKey != "" && batchAttachRequest .UnitNumber != "" {
421
- return fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
428
+ if batchAttachRequest .ControllerKey != "" || batchAttachRequest .UnitNumber != "" {
429
+ return batchAttachRequest , fmt .Errorf ("incorrect input for PVC %s in namespace %s with accessMode %s. " +
422
430
"ControllerNumber and UnitNumber must not be provided with RWO accessMode" , pvcName , namespace , accessMode )
423
431
}
424
432
}
425
433
}
426
434
427
435
log .Infof ("Validated request for PVC %s in namespace %s" , pvcName , namespace )
428
436
429
- return nil
437
+ return batchAttachRequest , nil
430
438
}
431
439
432
440
// getVmObject find the VM object on vCenter.
0 commit comments