From 4bca5d704f4293ff22139d5af3f9aa9e89ba122d Mon Sep 17 00:00:00 2001 From: Francesco Pantano Date: Wed, 6 Nov 2024 14:30:03 +0100 Subject: [PATCH] Do not use strings.TrimPrefix to get ShareName As done with cinder as part of [1], to make manila consistent with that work, this patch removes the need of using strings.TrimPrefix and instead relies on ShareName() function, that returns the instance name stored as label in every manilaShare instance. [1] https://github.com/openstack-k8s-operators/cinder-operator/pull/463 Signed-off-by: Francesco Pantano --- pkg/manila/volumes.go | 6 ------ pkg/manilashare/statefulset.go | 6 ++++-- pkg/manilashare/volumes.go | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/manila/volumes.go b/pkg/manila/volumes.go index 24ad4543..f064def2 100644 --- a/pkg/manila/volumes.go +++ b/pkg/manila/volumes.go @@ -48,12 +48,6 @@ func GetVolumes(name string, extraVol []manilav1.ManilaExtraVolMounts, svc []sto }, }, }, - /*{ - Name: "config-data-merged", - VolumeSource: corev1.VolumeSource{ - EmptyDir: &corev1.EmptyDirVolumeSource{Medium: ""}, - }, - },*/ } for _, exv := range extraVol { diff --git a/pkg/manilashare/statefulset.go b/pkg/manilashare/statefulset.go index 5c68fc06..bb3474e1 100644 --- a/pkg/manilashare/statefulset.go +++ b/pkg/manilashare/statefulset.go @@ -81,11 +81,13 @@ func StatefulSet( volumes := GetVolumes( manila.GetOwningManilaName(instance), instance.Name, - instance.Spec.ExtraMounts) + instance.Spec.ExtraMounts, + instance.ShareName(), + ) volumeMounts := GetVolumeMounts( - instance.Name, instance.Spec.ExtraMounts, + instance.ShareName(), ) // Add the CA bundle diff --git a/pkg/manilashare/volumes.go b/pkg/manilashare/volumes.go index 0fc264be..fbefd07e 100644 --- a/pkg/manilashare/volumes.go +++ b/pkg/manilashare/volumes.go @@ -5,11 +5,15 @@ import ( manilav1 "github.com/openstack-k8s-operators/manila-operator/api/v1beta1" "github.com/openstack-k8s-operators/manila-operator/pkg/manila" corev1 "k8s.io/api/core/v1" - "strings" ) // GetVolumes - -func GetVolumes(parentName string, name string, extraVol []manilav1.ManilaExtraVolMounts) []corev1.Volume { +func GetVolumes( + parentName string, + name string, + extraVol []manilav1.ManilaExtraVolMounts, + propagationInstanceName string, +) []corev1.Volume { var config0644AccessMode int32 = 0644 var dirOrCreate = corev1.HostPathDirectoryOrCreate @@ -35,12 +39,15 @@ func GetVolumes(parentName string, name string, extraVol []manilav1.ManilaExtraV } // Set the propagation levels for ManilaShare, including the backend name - propagation := append(manila.ManilaSharePropagation, storage.PropagationType(strings.TrimPrefix(name, "manila-share-"))) + propagation := append(manila.ManilaSharePropagation, storage.PropagationType(propagationInstanceName)) return append(manila.GetVolumes(parentName, extraVol, propagation), shareVolumes...) } // GetVolumeMounts - Manila Share VolumeMounts -func GetVolumeMounts(name string, extraVol []manilav1.ManilaExtraVolMounts) []corev1.VolumeMount { +func GetVolumeMounts( + extraVol []manilav1.ManilaExtraVolMounts, + propagationInstanceName string, +) []corev1.VolumeMount { shareVolumeMounts := []corev1.VolumeMount{ { Name: "config-data-custom", @@ -59,6 +66,6 @@ func GetVolumeMounts(name string, extraVol []manilav1.ManilaExtraVolMounts) []co } // Set the propagation levels for ManilaShare, including the backend name - propagation := append(manila.ManilaSharePropagation, storage.PropagationType(strings.TrimPrefix(name, "manila-share-"))) + propagation := append(manila.ManilaSharePropagation, storage.PropagationType(propagationInstanceName)) return append(manila.GetVolumeMounts(extraVol, propagation), shareVolumeMounts...) }