|
4 | 4 | package server_test |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + storagev1alpha1 "github.com/ironcore-dev/ironcore/api/storage/v1alpha1" |
| 8 | + volumebrokerv1alpha1 "github.com/ironcore-dev/ironcore/broker/volumebroker/api/v1alpha1" |
7 | 9 | irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" |
8 | 10 | iri "github.com/ironcore-dev/ironcore/iri/apis/volume/v1alpha1" |
| 11 | + poolletutils "github.com/ironcore-dev/ironcore/poollet/common/utils" |
9 | 12 | volumepoolletv1alpha1 "github.com/ironcore-dev/ironcore/poollet/volumepoollet/api/v1alpha1" |
10 | 13 | . "github.com/onsi/ginkgo/v2" |
11 | 14 | . "github.com/onsi/gomega" |
| 15 | + "sigs.k8s.io/controller-runtime/pkg/client" |
12 | 16 | ) |
13 | 17 |
|
14 | 18 | var _ = Describe("ListVolumes", func() { |
15 | | - _, srv := SetupTest() |
| 19 | + ns, srv := SetupTest() |
16 | 20 | volumeClass := SetupVolumeClass() |
17 | 21 |
|
18 | 22 | It("should correctly list volumes", func(ctx SpecContext) { |
@@ -44,4 +48,58 @@ var _ = Describe("ListVolumes", func() { |
44 | 48 | By("listing the Volumes") |
45 | 49 | Expect(srv.ListVolumes(ctx, &iri.ListVolumesRequest{})).To(HaveField("Volumes", ConsistOf(Volumes...))) |
46 | 50 | }) |
| 51 | + |
| 52 | + It("should set volume uid label to all existing volumes", func(ctx SpecContext) { |
| 53 | + By("creating multiple volumes") |
| 54 | + res, err := srv.CreateVolume(ctx, &iri.CreateVolumeRequest{ |
| 55 | + Volume: &iri.Volume{ |
| 56 | + Metadata: &irimeta.ObjectMetadata{ |
| 57 | + Labels: map[string]string{ |
| 58 | + volumepoolletv1alpha1.VolumeUIDLabel: "foobar", |
| 59 | + }, |
| 60 | + }, |
| 61 | + Spec: &iri.VolumeSpec{ |
| 62 | + Class: volumeClass.Name, |
| 63 | + Resources: &iri.VolumeResources{ |
| 64 | + StorageBytes: 100, |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }) |
| 69 | + Expect(err).NotTo(HaveOccurred()) |
| 70 | + Expect(res).NotTo(BeNil()) |
| 71 | + |
| 72 | + ironcoreVolume := &storagev1alpha1.Volume{} |
| 73 | + ironcoreVolumeKey := client.ObjectKey{Namespace: ns.Name, Name: res.Volume.Metadata.Id} |
| 74 | + Expect(k8sClient.Get(ctx, ironcoreVolumeKey, ironcoreVolume)).To(Succeed()) |
| 75 | + Expect(ironcoreVolume.Labels).To(Equal(map[string]string{ |
| 76 | + poolletutils.DownwardAPILabel(volumepoolletv1alpha1.VolumeDownwardAPIPrefix, "root-volume-uid"): "foobar", |
| 77 | + volumebrokerv1alpha1.CreatedLabel: "true", |
| 78 | + volumebrokerv1alpha1.ManagerLabel: volumebrokerv1alpha1.VolumeBrokerManager, |
| 79 | + volumepoolletv1alpha1.VolumeUIDLabel: "foobar", |
| 80 | + })) |
| 81 | + |
| 82 | + base := ironcoreVolume.DeepCopy() |
| 83 | + delete(ironcoreVolume.Labels, volumepoolletv1alpha1.VolumeUIDLabel) |
| 84 | + Expect(k8sClient.Patch(ctx, ironcoreVolume, client.MergeFrom(base))).To(Succeed()) |
| 85 | + Expect(k8sClient.Get(ctx, ironcoreVolumeKey, ironcoreVolume)).To(Succeed()) |
| 86 | + Expect(ironcoreVolume.Labels).To(Equal(map[string]string{ |
| 87 | + poolletutils.DownwardAPILabel(volumepoolletv1alpha1.VolumeDownwardAPIPrefix, "root-volume-uid"): "foobar", |
| 88 | + volumebrokerv1alpha1.CreatedLabel: "true", |
| 89 | + volumebrokerv1alpha1.ManagerLabel: volumebrokerv1alpha1.VolumeBrokerManager, |
| 90 | + })) |
| 91 | + |
| 92 | + Expect(srv.SetVolumeUIDLabelToAllVolumes(ctx)).NotTo(HaveOccurred()) |
| 93 | + |
| 94 | + By("getting the ironcore volume") |
| 95 | + Expect(k8sClient.Get(ctx, ironcoreVolumeKey, ironcoreVolume)).To(Succeed()) |
| 96 | + |
| 97 | + By("inspecting the ironcore volume") |
| 98 | + Expect(ironcoreVolume.Labels).To(Equal(map[string]string{ |
| 99 | + poolletutils.DownwardAPILabel(volumepoolletv1alpha1.VolumeDownwardAPIPrefix, "root-volume-uid"): "foobar", |
| 100 | + volumebrokerv1alpha1.CreatedLabel: "true", |
| 101 | + volumebrokerv1alpha1.ManagerLabel: volumebrokerv1alpha1.VolumeBrokerManager, |
| 102 | + volumepoolletv1alpha1.VolumeUIDLabel: "foobar", |
| 103 | + })) |
| 104 | + }) |
47 | 105 | }) |
0 commit comments