Skip to content

Commit

Permalink
fix local pvc naming
Browse files Browse the repository at this point in the history
  • Loading branch information
aleoli authored and adamjensenbot committed Nov 26, 2021
1 parent b3099f2 commit c9227cb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/consts/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ const (

// StorageAvailableLabel is the label used to mark if the liqo storage is available on a virtual node.
StorageAvailableLabel = "storage.liqo.io/available"

// VirtualPvcNamespaceLabel is the label used to mark the namespace of a virtual PVC.
VirtualPvcNamespaceLabel = "storage.liqo.io/virtual-pvc-namespace"
// VirtualPvcNameLabel is the label used to mark the name of a virtual PVC.
VirtualPvcNameLabel = "storage.liqo.io/virtual-pvc-name"
)
2 changes: 1 addition & 1 deletion pkg/liqo-controller-manager/storageprovisioner/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
func (p *liqoLocalStorageProvisioner) Delete(ctx context.Context, volume *v1.PersistentVolume) error {
realPvc := v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: volume.Spec.ClaimRef.Name,
Name: string(volume.Spec.ClaimRef.UID),
Namespace: p.storageNamespace,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (
func (p *liqoLocalStorageProvisioner) provisionLocalPVC(ctx context.Context,
options controller.ProvisionOptions) (*v1.PersistentVolume, controller.ProvisioningState, error) {
virtualPvc := options.PVC
realPvcName := virtualPvc.GetUID()
realPvc := v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: virtualPvc.Name,
Name: string(realPvcName),
Namespace: p.storageNamespace,
},
}
Expand Down Expand Up @@ -108,6 +109,12 @@ func (p *liqoLocalStorageProvisioner) mutateLocalRealPVC(virtualPvc, realPvc *v1
realPvc.ObjectMeta.Annotations["volume.kubernetes.io/selected-node"] = selectedNode.Name
realPvc.ObjectMeta.Annotations["volume.alpha.kubernetes.io/selected-node"] = selectedNode.Name

if realPvc.ObjectMeta.Labels == nil {
realPvc.ObjectMeta.Labels = map[string]string{}
}
realPvc.ObjectMeta.Labels[consts.VirtualPvcNamespaceLabel] = virtualPvc.GetNamespace()
realPvc.ObjectMeta.Labels[consts.VirtualPvcNameLabel] = virtualPvc.GetName()

storageClassName := realPvc.Spec.StorageClassName
if p.localRealStorageClass != "" {
storageClassName = &p.localRealStorageClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var _ = Describe("Test Storage Provisioner", func() {
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
UID: "uuid",
},
Spec: corev1.PersistentVolumeClaimSpec{
Resources: corev1.ResourceRequirements{
Expand Down Expand Up @@ -182,7 +183,7 @@ var _ = Describe("Test Storage Provisioner", func() {

var realPvc corev1.PersistentVolumeClaim
Expect(k8sClient.Get(ctx, apitypes.NamespacedName{
Name: c.pvc.GetName(),
Name: string(c.pvc.GetUID()),
Namespace: storageNamespace,
}, &realPvc)).To(Succeed())

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

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

0 comments on commit c9227cb

Please sign in to comment.