Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions broker/volumebroker/server/event_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var _ = Describe("ListEvents", func() {
res, err := srv.CreateVolume(ctx, &iri.CreateVolumeRequest{
Volume: &iri.Volume{
Metadata: &irimeta.ObjectMetadata{
Id: "foo",
Labels: map[string]string{
volumepoolletv1alpha1.VolumeUIDLabel: "foobar",
},
Expand All @@ -53,6 +54,10 @@ var _ = Describe("ListEvents", func() {
Expect(err).NotTo(HaveOccurred())
Expect(res).NotTo(BeNil())

DeferCleanup(srv.DeleteVolume, &iri.DeleteVolumeRequest{
VolumeId: res.Volume.Metadata.Id,
})

By("getting the ironcore volume")
ironcoreVolume := &storagev1alpha1.Volume{}
ironcoreVolumeKey := client.ObjectKey{Namespace: ns.Name, Name: res.Volume.Metadata.Id}
Expand Down
2 changes: 1 addition & 1 deletion broker/volumebroker/server/volume_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *Server) getIronCoreVolumeConfig(_ context.Context, volume *iri.Volume)
ironcoreVolume := &storagev1alpha1.Volume{
ObjectMeta: metav1.ObjectMeta{
Namespace: s.namespace,
Name: s.idGen.Generate(),
Name: volume.Metadata.Id,
Labels: utilsmaps.AppendMap(labels, map[string]string{
volumebrokerv1alpha1.ManagerLabel: volumebrokerv1alpha1.VolumeBrokerManager,
}),
Expand Down
5 changes: 5 additions & 0 deletions broker/volumebroker/server/volume_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var _ = Describe("CreateVolume", func() {
res, err := srv.CreateVolume(ctx, &iri.CreateVolumeRequest{
Volume: &iri.Volume{
Metadata: &irimeta.ObjectMetadata{
Id: "foo",
Labels: map[string]string{
volumepoolletv1alpha1.VolumeUIDLabel: "foobar",
},
Expand All @@ -43,6 +44,10 @@ var _ = Describe("CreateVolume", func() {
Expect(err).NotTo(HaveOccurred())
Expect(res).NotTo(BeNil())

DeferCleanup(srv.DeleteVolume, &iri.DeleteVolumeRequest{
VolumeId: res.Volume.Metadata.Id,
})

By("getting the ironcore volume")
ironcoreVolume := &storagev1alpha1.Volume{}
ironcoreVolumeKey := client.ObjectKey{Namespace: ns.Name, Name: res.Volume.Metadata.Id}
Expand Down
1 change: 1 addition & 0 deletions broker/volumebroker/server/volume_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var _ = Describe("DeleteVolume", func() {
createRes, err := srv.CreateVolume(ctx, &iri.CreateVolumeRequest{
Volume: &iri.Volume{
Metadata: &irimeta.ObjectMetadata{
Id: "foo",
Labels: map[string]string{
volumepoolletv1alpha1.VolumeUIDLabel: "foobar",
},
Expand Down
5 changes: 5 additions & 0 deletions broker/volumebroker/server/volume_expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var _ = Describe("ExpandVolume", func() {
createRes, err := srv.CreateVolume(ctx, &iri.CreateVolumeRequest{
Volume: &iri.Volume{
Metadata: &irimeta.ObjectMetadata{
Id: "foo",
Labels: map[string]string{
volumepoolletv1alpha1.VolumeUIDLabel: "foobar",
},
Expand All @@ -56,6 +57,10 @@ var _ = Describe("ExpandVolume", func() {
Expect(err).NotTo(HaveOccurred())
Expect(createRes).NotTo(BeNil())

DeferCleanup(srv.DeleteVolume, &iri.DeleteVolumeRequest{
VolumeId: createRes.Volume.Metadata.Id,
})

By("checking the volume storage size")
ironcoreVolume := &storagev1alpha1.Volume{}
ironcoreVolumeKey := client.ObjectKey{Namespace: ns.Name, Name: createRes.Volume.Metadata.Id}
Expand Down
7 changes: 7 additions & 0 deletions broker/volumebroker/server/volume_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package server_test

import (
"strconv"

irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1"
iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1"
volumepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/volumepoollet/api/v1alpha1"
Expand All @@ -24,6 +26,7 @@ var _ = Describe("ListVolumes", func() {
res, err := srv.CreateVolume(ctx, &iri.CreateVolumeRequest{
Volume: &iri.Volume{
Metadata: &irimeta.ObjectMetadata{
Id: "foo" + strconv.Itoa(i),
Labels: map[string]string{
volumepoolletv1alpha1.VolumeUIDLabel: "foobar",
},
Expand All @@ -39,6 +42,10 @@ var _ = Describe("ListVolumes", func() {
Expect(err).NotTo(HaveOccurred())
Expect(res).NotTo(BeNil())
Volumes[i] = res.Volume

DeferCleanup(srv.DeleteVolume, &iri.DeleteVolumeRequest{
VolumeId: res.Volume.Metadata.Id,
})
}

By("listing the Volumes")
Expand Down
1 change: 0 additions & 1 deletion iri/testing/volume/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func (r *FakeRuntimeService) CreateVolume(ctx context.Context, req *iri.CreateVo
defer r.Unlock()

volume := req.Volume
volume.Metadata.Id = r.idGen.Generate()
volume.Metadata.CreatedAt = time.Now().UnixNano()
volume.Status = &iri.VolumeStatus{}

Expand Down
47 changes: 14 additions & 33 deletions poollet/volumepoollet/controllers/volume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,14 @@ func (r *VolumeReconciler) iriVolumeAnnotations(_ *storagev1alpha1.Volume) map[s
return map[string]string{}
}

func (r *VolumeReconciler) listIRIVolumesByKey(ctx context.Context, volumeKey client.ObjectKey) ([]*iri.Volume, error) {
func (r *VolumeReconciler) getIRIVolumeByID(ctx context.Context, volumeID types.UID) ([]*iri.Volume, error) {
res, err := r.VolumeRuntime.ListVolumes(ctx, &iri.ListVolumesRequest{
Filter: &iri.VolumeFilter{
LabelSelector: map[string]string{
volumepoolletv1alpha1.VolumeNamespaceLabel: volumeKey.Namespace,
volumepoolletv1alpha1.VolumeNameLabel: volumeKey.Name,
},
Id: string(volumeID),
},
})
if err != nil {
return nil, fmt.Errorf("error listing volumes by key: %w", err)
}
volumes := res.Volumes
return volumes, nil
}

func (r *VolumeReconciler) listIRIVolumesByUID(ctx context.Context, volumeUID types.UID) ([]*iri.Volume, error) {
res, err := r.VolumeRuntime.ListVolumes(ctx, &iri.ListVolumesRequest{
Filter: &iri.VolumeFilter{
LabelSelector: map[string]string{
volumepoolletv1alpha1.VolumeUIDLabel: string(volumeUID),
},
},
})
if err != nil {
return nil, fmt.Errorf("error listing volumes by uid: %w", err)
return nil, fmt.Errorf("error listing volumes by id: %w", err)
}
return res.Volumes, nil
}
Expand All @@ -124,18 +106,18 @@ func (r *VolumeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("error getting volume %s: %w", req.NamespacedName, err)
}
return r.deleteGone(ctx, log, req.NamespacedName)
return r.deleteGone(ctx, log, volume.UID)
}
return r.reconcileExists(ctx, log, volume)
}

func (r *VolumeReconciler) deleteGone(ctx context.Context, log logr.Logger, volumeKey client.ObjectKey) (ctrl.Result, error) {
func (r *VolumeReconciler) deleteGone(ctx context.Context, log logr.Logger, volumeUID types.UID) (ctrl.Result, error) {
log.V(1).Info("Delete gone")

log.V(1).Info("Listing iri volumes by key")
volumes, err := r.listIRIVolumesByKey(ctx, volumeKey)
log.V(1).Info("Listing iri volumes by Id")
volumes, err := r.getIRIVolumeByID(ctx, volumeUID)
if err != nil {
return ctrl.Result{}, fmt.Errorf("error listing iri volumes by key: %w", err)
return ctrl.Result{}, fmt.Errorf("error listing iri volumes by Id: %w", err)
}

ok, err := r.deleteIRIVolumes(ctx, log, volumes)
Expand Down Expand Up @@ -206,7 +188,7 @@ func (r *VolumeReconciler) delete(ctx context.Context, log logr.Logger, volume *
log.V(1).Info("Finalizer present")

log.V(1).Info("Listing volumes")
volumes, err := r.listIRIVolumesByUID(ctx, volume.UID)
volumes, err := r.getIRIVolumeByID(ctx, volume.UID)
if err != nil {
return ctrl.Result{}, fmt.Errorf("error listing volumes by uid: %w", err)
}
Expand Down Expand Up @@ -245,6 +227,7 @@ func (r *VolumeReconciler) prepareIRIVolumeMetadata(volume *storagev1alpha1.Volu
errs = append(errs, fmt.Errorf("error preparing iri volume labels: %w", err))
}
return &irimeta.ObjectMetadata{
Id: string(volume.UID),
Labels: labels,
Annotations: r.iriVolumeAnnotations(volume),
}, errs
Expand Down Expand Up @@ -375,9 +358,7 @@ func (r *VolumeReconciler) reconcile(ctx context.Context, log logr.Logger, volum
log.V(1).Info("Listing volumes")
res, err := r.VolumeRuntime.ListVolumes(ctx, &iri.ListVolumesRequest{
Filter: &iri.VolumeFilter{
LabelSelector: map[string]string{
volumepoolletv1alpha1.VolumeUIDLabel: string(volume.UID),
},
Id: string(volume.UID),
},
})
if err != nil {
Expand Down Expand Up @@ -415,7 +396,7 @@ func (r *VolumeReconciler) create(ctx context.Context, log logr.Logger, volume *
return ctrl.Result{}, nil
}

log.V(1).Info("Creating volume")
log.V(1).Info("Creating volume", "volume before ", iriVolume)
res, err := r.VolumeRuntime.CreateVolume(ctx, &iri.CreateVolumeRequest{
Volume: iriVolume,
})
Expand All @@ -427,14 +408,14 @@ func (r *VolumeReconciler) create(ctx context.Context, log logr.Logger, volume *

volumeID := iriVolume.Metadata.Id
log = log.WithValues("VolumeID", volumeID)
log.V(1).Info("Created")
log.V(1).Info("Created", "volume after ", iriVolume)

log.V(1).Info("Updating status")
if err := r.updateStatus(ctx, log, volume, iriVolume); err != nil {
return ctrl.Result{}, fmt.Errorf("error updating volume status: %w", err)
}

log.V(1).Info("Created")
log.V(1).Info("Created", "volume after ", iriVolume)
return ctrl.Result{}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions poollet/volumepoollet/controllers/volume_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var _ = Describe("VolumeController", func() {

_, iriVolume := GetSingleMapEntry(srv.Volumes)

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

_, iriVolume := GetSingleMapEntry(srv.Volumes)

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

_, iriVolume := GetSingleMapEntry(srv.Volumes)

Expect(iriVolume.Metadata.Id).To(Equal(string(volume.UID)))
Expect(iriVolume.Spec.Image).To(Equal(""))
Expect(iriVolume.Spec.Class).To(Equal(expandableVc.Name))
Expect(iriVolume.Spec.Resources.StorageBytes).To(Equal(size.Value()))
Expand Down
Loading