From 32ae0529d20b357100e1e1e93d79e16004b2f131 Mon Sep 17 00:00:00 2001 From: Travis Nielsen Date: Fri, 9 Dec 2022 12:43:17 -0700 Subject: [PATCH] osd: replace dot with dash in pvc names The volume names of a pod must follow the standard naming convention which does not allow periods in the name. Since the device set name is used as the pvc name and then the volume name to attach to the osd prepare job, we must sanitize the name for the invalid character and replace it. Signed-off-by: Travis Nielsen (cherry picked from commit 4a70d3489d31ebbf3133a444b242ad0e21e73421) --- pkg/operator/ceph/cluster/osd/deviceSet.go | 1 + pkg/operator/ceph/cluster/osd/deviceset_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/operator/ceph/cluster/osd/deviceSet.go b/pkg/operator/ceph/cluster/osd/deviceSet.go index df150b210..e06be8773 100644 --- a/pkg/operator/ceph/cluster/osd/deviceSet.go +++ b/pkg/operator/ceph/cluster/osd/deviceSet.go @@ -290,5 +290,6 @@ func legacyDeviceSetPVCID(deviceSetName string, setIndex int) string { // It includes the pvcTemplateName in it func deviceSetPVCID(deviceSetName, pvcTemplateName string, setIndex int) string { cleanName := strings.Replace(pvcTemplateName, " ", "-", -1) + deviceSetName = strings.Replace(deviceSetName, ".", "-", -1) return fmt.Sprintf("%s-%s-%d", deviceSetName, cleanName, setIndex) } diff --git a/pkg/operator/ceph/cluster/osd/deviceset_test.go b/pkg/operator/ceph/cluster/osd/deviceset_test.go index db9cb180f..5f5ada985 100644 --- a/pkg/operator/ceph/cluster/osd/deviceset_test.go +++ b/pkg/operator/ceph/cluster/osd/deviceset_test.go @@ -270,3 +270,17 @@ func TestPrepareDeviceSetsWithCrushParams(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 1, len(pvcs.Items)) } + +func TestPVCName(t *testing.T) { + id := deviceSetPVCID("mydeviceset", "a", 0) + assert.Equal(t, "mydeviceset-a-0", id) + + id = deviceSetPVCID("mydeviceset", "a", 10) + assert.Equal(t, "mydeviceset-a-10", id) + + id = deviceSetPVCID("device-set", "a", 10) + assert.Equal(t, "device-set-a-10", id) + + id = deviceSetPVCID("device.set.with.dots", "b", 10) + assert.Equal(t, "device-set-with-dots-b-10", id) +}