@@ -221,13 +221,13 @@ func getIRIVolumeClassCapabilities(volumeClass *storagev1alpha1.VolumeClass) *ir
221221 }
222222}
223223
224- func (r * VolumeReconciler ) prepareIRIVolumeMetadata (volume * storagev1alpha1.Volume , errs []error ) (* irimeta.ObjectMetadata , []error ) {
224+ func (r * VolumeReconciler ) prepareIRIVolumeMetadata (volume * storagev1alpha1.Volume , iriVolumeId string , errs []error ) (* irimeta.ObjectMetadata , []error ) {
225225 labels , err := r .iriVolumeLabels (volume )
226226 if err != nil {
227227 errs = append (errs , fmt .Errorf ("error preparing iri volume labels: %w" , err ))
228228 }
229229 return & irimeta.ObjectMetadata {
230- Id : string ( volume . UID ) ,
230+ Id : iriVolumeId ,
231231 Labels : labels ,
232232 Annotations : r .iriVolumeAnnotations (volume ),
233233 }, errs
@@ -286,7 +286,7 @@ func (r *VolumeReconciler) prepareIRIVolumeResources(resources corev1alpha1.Reso
286286 }
287287}
288288
289- func (r * VolumeReconciler ) prepareIRIVolume (ctx context.Context , log logr.Logger , volume * storagev1alpha1.Volume ) (* iri.Volume , bool , error ) {
289+ func (r * VolumeReconciler ) prepareIRIVolume (ctx context.Context , log logr.Logger , volume * storagev1alpha1.Volume , iriVolumeId string ) (* iri.Volume , bool , error ) {
290290 var (
291291 ok = true
292292 errs []error
@@ -311,7 +311,7 @@ func (r *VolumeReconciler) prepareIRIVolume(ctx context.Context, log logr.Logger
311311 }
312312
313313 resources := r .prepareIRIVolumeResources (volume .Spec .Resources )
314- metadata , errs := r .prepareIRIVolumeMetadata (volume , errs )
314+ metadata , errs := r .prepareIRIVolumeMetadata (volume , iriVolumeId , errs )
315315
316316 if len (errs ) > 0 {
317317 return nil , false , fmt .Errorf ("error(s) preparing iri volume: %v" , errs )
@@ -334,6 +334,17 @@ func (r *VolumeReconciler) prepareIRIVolume(ctx context.Context, log logr.Logger
334334func (r * VolumeReconciler ) reconcile (ctx context.Context , log logr.Logger , volume * storagev1alpha1.Volume ) (ctrl.Result , error ) {
335335 log .V (1 ).Info ("Reconcile" )
336336
337+ log .V (1 ).Info ("Get version of volume runtime" )
338+ version , err := r .VolumeRuntime .Version (ctx , & iri.VersionRequest {})
339+ if err != nil {
340+ return ctrl.Result {}, fmt .Errorf ("error getting volume runtime version: %w" , err )
341+ }
342+
343+ log .V (1 ).Info ("Generate iri volume Id using version info and volume uid" )
344+ iriVolumeId := r .generateName (string (volume .UID ), version .RuntimeName + version .RuntimeVersion )
345+
346+ log = log .WithValues ("VolumeID" , iriVolumeId )
347+
337348 log .V (1 ).Info ("Ensuring finalizer" )
338349 modified , err := clientutils .PatchEnsureFinalizer (ctx , r .Client , volume , volumepoolletv1alpha1 .VolumeFinalizer )
339350 if err != nil {
@@ -358,7 +369,7 @@ func (r *VolumeReconciler) reconcile(ctx context.Context, log logr.Logger, volum
358369 log .V (1 ).Info ("Listing volumes" )
359370 res , err := r .VolumeRuntime .ListVolumes (ctx , & iri.ListVolumesRequest {
360371 Filter : & iri.VolumeFilter {
361- Id : string ( volume . UID ) ,
372+ Id : iriVolumeId ,
362373 },
363374 })
364375 if err != nil {
@@ -367,7 +378,7 @@ func (r *VolumeReconciler) reconcile(ctx context.Context, log logr.Logger, volum
367378
368379 switch len (res .Volumes ) {
369380 case 0 :
370- return r .create (ctx , log , volume )
381+ return r .create (ctx , log , volume , iriVolumeId )
371382 case 1 :
372383 iriVolume := res .Volumes [0 ]
373384 if err := r .update (ctx , log , volume , iriVolume ); err != nil {
@@ -383,11 +394,11 @@ func (r *VolumeReconciler) reconcile(ctx context.Context, log logr.Logger, volum
383394 }
384395}
385396
386- func (r * VolumeReconciler ) create (ctx context.Context , log logr.Logger , volume * storagev1alpha1.Volume ) (ctrl.Result , error ) {
397+ func (r * VolumeReconciler ) create (ctx context.Context , log logr.Logger , volume * storagev1alpha1.Volume , iriVolumeId string ) (ctrl.Result , error ) {
387398 log .V (1 ).Info ("Create" )
388399
389400 log .V (1 ).Info ("Preparing iri volume" )
390- iriVolume , ok , err := r .prepareIRIVolume (ctx , log , volume )
401+ iriVolume , ok , err := r .prepareIRIVolume (ctx , log , volume , iriVolumeId )
391402 if err != nil {
392403 return ctrl.Result {}, fmt .Errorf ("error preparing iri volume: %w" , err )
393404 }
@@ -396,26 +407,20 @@ func (r *VolumeReconciler) create(ctx context.Context, log logr.Logger, volume *
396407 return ctrl.Result {}, nil
397408 }
398409
399- log .V (1 ).Info ("Creating volume" , " volume before " , iriVolume )
410+ log .V (1 ).Info ("Creating iri volume" )
400411 res , err := r .VolumeRuntime .CreateVolume (ctx , & iri.CreateVolumeRequest {
401412 Volume : iriVolume ,
402413 })
403414 if err != nil {
404415 return ctrl.Result {}, fmt .Errorf ("error creating volume: %w" , err )
405416 }
406417
407- iriVolume = res .Volume
408-
409- volumeID := iriVolume .Metadata .Id
410- log = log .WithValues ("VolumeID" , volumeID )
411- log .V (1 ).Info ("Created" , "volume after " , iriVolume )
412-
413- log .V (1 ).Info ("Updating status" )
414- if err := r .updateStatus (ctx , log , volume , iriVolume ); err != nil {
418+ log .V (1 ).Info ("Updating iri volume status" )
419+ if err := r .updateStatus (ctx , log , volume , res .Volume ); err != nil {
415420 return ctrl.Result {}, fmt .Errorf ("error updating volume status: %w" , err )
416421 }
417422
418- log .V (1 ).Info ("Created" , "volume after " , iriVolume )
423+ log .V (1 ).Info ("Created and updated iri volume status" )
419424 return ctrl.Result {}, nil
420425}
421426
@@ -437,8 +442,8 @@ func (r *VolumeReconciler) update(ctx context.Context, log logr.Logger, volume *
437442 return nil
438443}
439444
440- func (r * VolumeReconciler ) volumeSecretName (volumeName , volumeHandle string ) string {
441- sum := sha256 .Sum256 ([]byte (fmt .Sprintf ("%s/%s" , volumeName , volumeHandle )))
445+ func (r * VolumeReconciler ) generateName (volumeName , suffix string ) string {
446+ sum := sha256 .Sum256 ([]byte (fmt .Sprintf ("%s/%s" , volumeName , suffix )))
442447 return hex .EncodeToString (sum [:])[:63 ]
443448}
444449
@@ -471,7 +476,7 @@ func (r *VolumeReconciler) updateStatus(ctx context.Context, log logr.Logger, vo
471476 },
472477 ObjectMeta : metav1.ObjectMeta {
473478 Namespace : volume .Namespace ,
474- Name : r .volumeSecretName (volume .Name , iriAccess .Handle ),
479+ Name : r .generateName (volume .Name , iriAccess .Handle ),
475480 Labels : map [string ]string {
476481 volumepoolletv1alpha1 .VolumeUIDLabel : string (volume .UID ),
477482 },
0 commit comments