Skip to content

Commit c9227cb

Browse files
aleoliadamjensenbot
authored andcommitted
fix local pvc naming
1 parent b3099f2 commit c9227cb

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

pkg/consts/storage.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ const (
2020

2121
// StorageAvailableLabel is the label used to mark if the liqo storage is available on a virtual node.
2222
StorageAvailableLabel = "storage.liqo.io/available"
23+
24+
// VirtualPvcNamespaceLabel is the label used to mark the namespace of a virtual PVC.
25+
VirtualPvcNamespaceLabel = "storage.liqo.io/virtual-pvc-namespace"
26+
// VirtualPvcNameLabel is the label used to mark the name of a virtual PVC.
27+
VirtualPvcNameLabel = "storage.liqo.io/virtual-pvc-name"
2328
)

pkg/liqo-controller-manager/storageprovisioner/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
func (p *liqoLocalStorageProvisioner) Delete(ctx context.Context, volume *v1.PersistentVolume) error {
2828
realPvc := v1.PersistentVolumeClaim{
2929
ObjectMeta: metav1.ObjectMeta{
30-
Name: volume.Spec.ClaimRef.Name,
30+
Name: string(volume.Spec.ClaimRef.UID),
3131
Namespace: p.storageNamespace,
3232
},
3333
}

pkg/liqo-controller-manager/storageprovisioner/localprovisioner.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import (
3131
func (p *liqoLocalStorageProvisioner) provisionLocalPVC(ctx context.Context,
3232
options controller.ProvisionOptions) (*v1.PersistentVolume, controller.ProvisioningState, error) {
3333
virtualPvc := options.PVC
34+
realPvcName := virtualPvc.GetUID()
3435
realPvc := v1.PersistentVolumeClaim{
3536
ObjectMeta: metav1.ObjectMeta{
36-
Name: virtualPvc.Name,
37+
Name: string(realPvcName),
3738
Namespace: p.storageNamespace,
3839
},
3940
}
@@ -108,6 +109,12 @@ func (p *liqoLocalStorageProvisioner) mutateLocalRealPVC(virtualPvc, realPvc *v1
108109
realPvc.ObjectMeta.Annotations["volume.kubernetes.io/selected-node"] = selectedNode.Name
109110
realPvc.ObjectMeta.Annotations["volume.alpha.kubernetes.io/selected-node"] = selectedNode.Name
110111

112+
if realPvc.ObjectMeta.Labels == nil {
113+
realPvc.ObjectMeta.Labels = map[string]string{}
114+
}
115+
realPvc.ObjectMeta.Labels[consts.VirtualPvcNamespaceLabel] = virtualPvc.GetNamespace()
116+
realPvc.ObjectMeta.Labels[consts.VirtualPvcNameLabel] = virtualPvc.GetName()
117+
111118
storageClassName := realPvc.Spec.StorageClassName
112119
if p.localRealStorageClass != "" {
113120
storageClassName = &p.localRealStorageClass

pkg/liqo-controller-manager/storageprovisioner/storageprovisioner_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ var _ = Describe("Test Storage Provisioner", func() {
7979
ObjectMeta: metav1.ObjectMeta{
8080
Name: name,
8181
Namespace: namespace,
82+
UID: "uuid",
8283
},
8384
Spec: corev1.PersistentVolumeClaimSpec{
8485
Resources: corev1.ResourceRequirements{
@@ -182,7 +183,7 @@ var _ = Describe("Test Storage Provisioner", func() {
182183

183184
var realPvc corev1.PersistentVolumeClaim
184185
Expect(k8sClient.Get(ctx, apitypes.NamespacedName{
185-
Name: c.pvc.GetName(),
186+
Name: string(c.pvc.GetUID()),
186187
Namespace: storageNamespace,
187188
}, &realPvc)).To(Succeed())
188189

@@ -191,6 +192,10 @@ var _ = Describe("Test Storage Provisioner", func() {
191192
} else {
192193
Expect(realPvc.Spec.StorageClassName).To(BeNil())
193194
}
195+
Expect(realPvc.Labels).To(HaveKey(liqoconst.VirtualPvcNamespaceLabel))
196+
Expect(realPvc.Labels).To(HaveKey(liqoconst.VirtualPvcNameLabel))
197+
Expect(realPvc.Labels[liqoconst.VirtualPvcNamespaceLabel]).To(Equal(c.pvc.GetNamespace()))
198+
Expect(realPvc.Labels[liqoconst.VirtualPvcNameLabel]).To(Equal(c.pvc.GetName()))
194199

195200
By("second attempt with no real pvc provisioned")
196201
pv, state, err = provisioner.provisionLocalPVC(ctx, forgeOpts())
@@ -301,6 +306,7 @@ var _ = Describe("Test Storage Provisioner", func() {
301306
ObjectMeta: metav1.ObjectMeta{
302307
Name: pvcName,
303308
Namespace: LocalNamespace,
309+
UID: "uuid",
304310
},
305311
Spec: corev1.PersistentVolumeClaimSpec{
306312
StorageClassName: pointer.String(virtualStorageClassName),

0 commit comments

Comments
 (0)