@@ -278,6 +278,23 @@ func (r *ReconcileCnsRegisterVolume) Reconcile(ctx context.Context,
278
278
return reconcile.Result {RequeueAfter : timeout }, nil
279
279
}
280
280
281
+ if instance .Spec .DiskURLPath != "" {
282
+ // if CNS Register Volume Instance is created with diskURLPath,
283
+ // confirm using CNS Volume ID, if another PV is already present with same volume ID
284
+ // If yes then fail.
285
+ pvName , found := commonco .ContainerOrchestratorUtility .GetPVNameFromCSIVolumeID (volInfo .VolumeID .Id )
286
+ if found {
287
+ if pvName != staticPvNamePrefix + volInfo .VolumeID .Id {
288
+ msg := fmt .Sprintf ("PV: %q with the volume ID: %q for volume path: %q" +
289
+ "is already present. Can not create multiple PV with same disk." , pvName , volInfo .VolumeID .Id ,
290
+ instance .Spec .DiskURLPath )
291
+ log .Errorf (msg )
292
+ setInstanceError (ctx , r , instance , msg )
293
+ return reconcile.Result {RequeueAfter : timeout }, nil
294
+ }
295
+ }
296
+ }
297
+
281
298
volumeID = volInfo .VolumeID .Id
282
299
log .Infof ("Created CNS volume with volumeID: %s" , volumeID )
283
300
@@ -685,6 +702,15 @@ func validateCnsRegisterVolumeSpec(ctx context.Context, instance *cnsregistervol
685
702
instance .Spec .AccessMode != v1 .ReadWriteOnce {
686
703
msg = fmt .Sprintf ("DiskURLPath cannot be used with accessMode: %q" , instance .Spec .AccessMode )
687
704
}
705
+ if instance .Spec .VolumeID != "" {
706
+ pvName , found := commonco .ContainerOrchestratorUtility .GetPVNameFromCSIVolumeID (instance .Spec .VolumeID )
707
+ if found {
708
+ if pvName != staticPvNamePrefix + instance .Spec .VolumeID {
709
+ msg = fmt .Sprintf ("PV: %q with the volume ID: %q " +
710
+ "is already present. Can not create multiple PV with same volume Id." , pvName , instance .Spec .VolumeID )
711
+ }
712
+ }
713
+ }
688
714
if msg != "" {
689
715
return errors .New (msg )
690
716
}
0 commit comments