Skip to content

Commit bdb637f

Browse files
committed
generate iri volume Id using volume uid and version suffix
1 parent bf6562c commit bdb637f

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

poollet/volumepoollet/controllers/volume_controller.go

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
334334
func (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
},

poollet/volumepoollet/controllers/volume_controller_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ var _ = Describe("VolumeController", func() {
6464

6565
_, iriVolume := GetSingleMapEntry(srv.Volumes)
6666

67-
Expect(iriVolume.Metadata.Id).To(Equal(string(volume.UID)))
6867
Expect(iriVolume.Spec.Image).To(Equal(""))
6968
Expect(iriVolume.Spec.Class).To(Equal(vc.Name))
7069
Expect(iriVolume.Spec.Encryption).To(BeNil())
@@ -157,7 +156,6 @@ var _ = Describe("VolumeController", func() {
157156

158157
_, iriVolume := GetSingleMapEntry(srv.Volumes)
159158

160-
Expect(iriVolume.Metadata.Id).To(Equal(string(volume.UID)))
161159
Expect(iriVolume.Spec.Image).To(Equal(""))
162160
Expect(iriVolume.Spec.Class).To(Equal(vc.Name))
163161
Expect(iriVolume.Spec.Resources.StorageBytes).To(Equal(size.Value()))
@@ -193,7 +191,6 @@ var _ = Describe("VolumeController", func() {
193191

194192
_, iriVolume := GetSingleMapEntry(srv.Volumes)
195193

196-
Expect(iriVolume.Metadata.Id).To(Equal(string(volume.UID)))
197194
Expect(iriVolume.Spec.Image).To(Equal(""))
198195
Expect(iriVolume.Spec.Class).To(Equal(expandableVc.Name))
199196
Expect(iriVolume.Spec.Resources.StorageBytes).To(Equal(size.Value()))

0 commit comments

Comments
 (0)