From 304734cf7daa2eced02c30a053a04c2b0f74b69b Mon Sep 17 00:00:00 2001 From: Yuma Ogami Date: Tue, 15 Nov 2022 07:17:57 +0000 Subject: [PATCH] osd: add expand-bluefs init container for host-based cluster OSD is not resized in host-based clusters even though expanding the backing block device. It's due to the lack of bluefs-bdev-expand init container. Closes: https://github.com/rook/rook/issues/10930 Signed-off-by: Yuma Ogami (cherry picked from commit 7599f1bc6b3f52479a815328409593e9430b00d9) --- pkg/operator/ceph/cluster/osd/spec.go | 26 ++++++++++++++++++++-- pkg/operator/ceph/cluster/osd/spec_test.go | 6 ++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/pkg/operator/ceph/cluster/osd/spec.go b/pkg/operator/ceph/cluster/osd/spec.go index 2a86c01d8..45d3a44dc 100644 --- a/pkg/operator/ceph/cluster/osd/spec.go +++ b/pkg/operator/ceph/cluster/osd/spec.go @@ -51,7 +51,7 @@ const ( blockPVCMetadataMapperInitContainer = "blkdevmapper-metadata" blockPVCWalMapperInitContainer = "blkdevmapper-wal" activatePVCOSDInitContainer = "activate" - expandPVCOSDInitContainer = "expand-bluefs" + expandOSDInitContainer = "expand-bluefs" expandEncryptedPVCOSDInitContainer = "expand-encrypted-bluefs" encryptedPVCStatusOSDInitContainer = "encrypted-block-status" encryptionKeyFileName = "luks_key" @@ -542,6 +542,7 @@ func (c *Cluster) makeDeployment(osdProps osdProperties, osd OSDInfo, provisionC volumes = append(volumes, activateOSDVolume...) volumeMounts = append(volumeMounts, activateOSDContainer.VolumeMounts[0]) initContainers = append(initContainers, *activateOSDContainer) + initContainers = append(initContainers, c.getExpandInitContainer(osdProps, c.spec.DataDirHostPath, c.clusterInfo.Namespace, osdID, osd)) } // Doing a chown in a post start lifecycle hook does not reliably complete before the OSD @@ -1167,7 +1168,7 @@ func (c *Cluster) getExpandPVCInitContainer(osdProps osdProperties, osdID string osdDataPath := activateOSDMountPath + osdID return v1.Container{ - Name: expandPVCOSDInitContainer, + Name: expandOSDInitContainer, Image: c.spec.CephVersion.Image, ImagePullPolicy: controller.GetContainerImagePullPolicy(c.spec.CephVersion.ImagePullPolicy), Command: []string{ @@ -1180,6 +1181,27 @@ func (c *Cluster) getExpandPVCInitContainer(osdProps osdProperties, osdID string } } +func (c *Cluster) getExpandInitContainer(osdProps osdProperties, configDir, namespace, osdID string, osdInfo OSDInfo) v1.Container { + // Output example is in the comments at the beginning of `getExpandPVCInitContainer()`. + osdDataPath := activateOSDMountPath + osdID + + return v1.Container{ + Name: expandOSDInitContainer, + Image: c.spec.CephVersion.Image, + ImagePullPolicy: controller.GetContainerImagePullPolicy(c.spec.CephVersion.ImagePullPolicy), + Command: []string{ + "ceph-bluestore-tool", + }, + Args: []string{"bluefs-bdev-expand", "--path", osdDataPath}, + VolumeMounts: []v1.VolumeMount{ + {Name: activateOSDVolumeName, MountPath: osdDataPath}, + {Name: "devices", MountPath: "/dev"}, + }, + SecurityContext: controller.PrivilegedContext(true), + Resources: osdProps.resources, + } +} + func (c *Cluster) getExpandEncryptedPVCInitContainer(mountPath string, osdProps osdProperties) v1.Container { /* Command example [root@rook-ceph-osd-0-59b9947547-w8mdq /]# cryptsetup resize set1-data-2-8n462-block-dmcrypt diff --git a/pkg/operator/ceph/cluster/osd/spec_test.go b/pkg/operator/ceph/cluster/osd/spec_test.go index 2d4fb540f..fe9d5cbc1 100644 --- a/pkg/operator/ceph/cluster/osd/spec_test.go +++ b/pkg/operator/ceph/cluster/osd/spec_test.go @@ -159,13 +159,17 @@ func testPodDevices(t *testing.T, dataDir, deviceName string, allDevices bool) { assert.Equal(t, c.clusterInfo.Namespace, deployment.Spec.Template.ObjectMeta.Labels["rook_cluster"]) assert.Equal(t, 1, len(deployment.Spec.Template.ObjectMeta.Annotations)) - assert.Equal(t, 2, len(deployment.Spec.Template.Spec.InitContainers)) + assert.Equal(t, 3, len(deployment.Spec.Template.Spec.InitContainers)) initCont := deployment.Spec.Template.Spec.InitContainers[0] assert.Equal(t, "quay.io/ceph/ceph:v15", initCont.Image) assert.Equal(t, "activate", initCont.Name) assert.Equal(t, 4, len(initCont.VolumeMounts)) initCont = deployment.Spec.Template.Spec.InitContainers[1] assert.Equal(t, "quay.io/ceph/ceph:v15", initCont.Image) + assert.Equal(t, "expand-bluefs", initCont.Name) + assert.Equal(t, 2, len(initCont.VolumeMounts)) + initCont = deployment.Spec.Template.Spec.InitContainers[2] + assert.Equal(t, "quay.io/ceph/ceph:v15", initCont.Image) assert.Equal(t, "chown-container-data-dir", initCont.Name) assert.Equal(t, 7, len(initCont.VolumeMounts))