From 13b63c4a08d0246dfa5ef2228be4879dfc2a7ccb Mon Sep 17 00:00:00 2001 From: Shinya Hayashi Date: Tue, 1 Nov 2022 08:41:19 +0000 Subject: [PATCH] osd: support loop devices for test clusters A new variable is added to rook-ceph-operator-config ConfigMap to allow using loop devices for osd. This feature is intended to be used for testing purposes only. Signed-off-by: Shinya Hayashi (cherry picked from commit 05875a3f4fb78b286297fb6c4ff90361dd5c62f0) --- .github/workflows/canary-integration-test.yml | 21 ++++-- Documentation/Helm-Charts/operator-chart.md | 1 + .../charts/rook-ceph/templates/configmap.yaml | 1 + deploy/charts/rook-ceph/values.yaml | 3 + deploy/examples/operator-openshift.yaml | 3 + deploy/examples/operator.yaml | 3 + pkg/clusterd/disk.go | 8 ++- pkg/daemon/ceph/osd/daemon.go | 17 +++++ pkg/daemon/ceph/osd/daemon_test.go | 53 ++++++++++++++ pkg/operator/ceph/cluster/cleanup.go | 3 + .../ceph/cluster/osd/provision_spec.go | 4 ++ pkg/operator/ceph/controller.go | 2 + .../ceph/controller/controller_utils.go | 17 +++++ .../ceph/controller/controller_utils_test.go | 14 ++++ pkg/operator/ceph/controller_test.go | 46 ++++++++++++ pkg/operator/discover/discover.go | 5 ++ pkg/util/sys/device.go | 4 +- tests/scripts/github-action-helper.sh | 24 +++++++ tests/scripts/loopDevicePV.sh | 71 +++++++++++++++++++ 19 files changed, 294 insertions(+), 6 deletions(-) create mode 100755 tests/scripts/loopDevicePV.sh diff --git a/.github/workflows/canary-integration-test.yml b/.github/workflows/canary-integration-test.yml index 393b832d3..0deddc5c0 100644 --- a/.github/workflows/canary-integration-test.yml +++ b/.github/workflows/canary-integration-test.yml @@ -238,14 +238,20 @@ jobs: BLOCK=$(sudo lsblk --paths|awk '/14G/ {print $1}'| head -1) tests/scripts/create-bluestore-partitions.sh --disk "$BLOCK" --wipe-only + - name: prepare loop devices for osds + run: | + tests/scripts/github-action-helper.sh prepare_loop_devices 1 + - name: deploy cluster - run: tests/scripts/github-action-helper.sh deploy_cluster + run: | + export ALLOW_LOOP_DEVICES=true + tests/scripts/github-action-helper.sh deploy_cluster loop - name: wait for prepare pod run: tests/scripts/github-action-helper.sh wait_for_prepare_pod - name: wait for ceph to be ready - run: tests/scripts/github-action-helper.sh wait_for_ceph_to_be_ready osd 1 + run: tests/scripts/github-action-helper.sh wait_for_ceph_to_be_ready osd 2 - name: check-ownerreferences run: tests/scripts/github-action-helper.sh check_ownerreferences @@ -507,17 +513,23 @@ jobs: tests/scripts/github-action-helper.sh use_local_disk tests/scripts/github-action-helper.sh create_partitions_for_osds + - name: prepare loop devices for osds + run: | + tests/scripts/github-action-helper.sh prepare_loop_devices 1 + - name: create cluster prerequisites run: | BLOCK=$(sudo lsblk --paths|awk '/14G/ {print $1}'| head -1) tests/scripts/localPathPV.sh "$BLOCK" + tests/scripts/loopDevicePV.sh 1 tests/scripts/github-action-helper.sh create_cluster_prerequisites - name: deploy cluster run: | + yq write -i deploy/examples/operator.yaml "data.ROOK_CEPH_ALLOW_LOOP_DEVICES" --style=double "true" tests/scripts/github-action-helper.sh deploy_manifest_with_local_build deploy/examples/operator.yaml yq write -i tests/manifests/test-cluster-on-pvc-encrypted.yaml "spec.storage.storageClassDeviceSets[0].encrypted" false - yq write -i tests/manifests/test-cluster-on-pvc-encrypted.yaml "spec.storage.storageClassDeviceSets[0].count" 2 + yq write -i tests/manifests/test-cluster-on-pvc-encrypted.yaml "spec.storage.storageClassDeviceSets[0].count" 3 yq write -i tests/manifests/test-cluster-on-pvc-encrypted.yaml "spec.storage.storageClassDeviceSets[0].volumeClaimTemplates[0].spec.resources.requests.storage" 6Gi kubectl create -f tests/manifests/test-cluster-on-pvc-encrypted.yaml tests/scripts/github-action-helper.sh deploy_manifest_with_local_build deploy/examples/toolbox.yaml @@ -526,7 +538,7 @@ jobs: run: tests/scripts/github-action-helper.sh wait_for_prepare_pod - name: wait for ceph to be ready - run: tests/scripts/github-action-helper.sh wait_for_ceph_to_be_ready osd 2 + run: tests/scripts/github-action-helper.sh wait_for_ceph_to_be_ready osd 3 - name: check-ownerreferences run: tests/scripts/github-action-helper.sh check_ownerreferences @@ -541,6 +553,7 @@ jobs: BLOCK=$(sudo lsblk --paths|awk '/14G/ {print $1}'| head -1) sudo head --bytes=60 ${BLOCK}1 sudo head --bytes=60 ${BLOCK}2 + sudo head --bytes=60 /dev/loop1 - name: collect common logs if: always() diff --git a/Documentation/Helm-Charts/operator-chart.md b/Documentation/Helm-Charts/operator-chart.md index 39af1d99f..04acd4466 100644 --- a/Documentation/Helm-Charts/operator-chart.md +++ b/Documentation/Helm-Charts/operator-chart.md @@ -57,6 +57,7 @@ The following tables lists the configurable parameters of the rook-operator char | `unreachableNodeTolerationSeconds` | Delay to use for the node.kubernetes.io/unreachable pod failure toleration to override the Kubernetes default of 5 minutes | `5s` | | `currentNamespaceOnly` | Whether the operator should watch cluster CRD in its own namespace or not | `false` | | `hostpathRequiresPrivileged` | Runs Ceph Pods as privileged to be able to write to `hostPath`s in OpenShift with SELinux restrictions. | `false` | +| `allowLoopDevices` | If true, loop devices are allowed to be used for osds in test clusters | `false` | | `discover.priorityClassName` | The priority class name to add to the discover pods | `` | | `discover.toleration` | Toleration for the discover pods | `` | | `discover.tolerationKey` | The specific key of the taint to tolerate | `` | diff --git a/deploy/charts/rook-ceph/templates/configmap.yaml b/deploy/charts/rook-ceph/templates/configmap.yaml index ab0897ace..9ca512f23 100644 --- a/deploy/charts/rook-ceph/templates/configmap.yaml +++ b/deploy/charts/rook-ceph/templates/configmap.yaml @@ -8,6 +8,7 @@ data: ROOK_LOG_LEVEL: {{ .Values.logLevel | quote }} ROOK_CEPH_COMMANDS_TIMEOUT_SECONDS: {{ .Values.cephCommandsTimeoutSeconds | quote }} ROOK_OBC_WATCH_OPERATOR_NAMESPACE: {{ .Values.enableOBCWatchOperatorNamespace | quote }} + ROOK_CEPH_ALLOW_LOOP_DEVICES: {{ .Values.allowLoopDevices | quote }} {{- if .Values.csi }} ROOK_CSI_ENABLE_RBD: {{ .Values.csi.enableRbdDriver | quote }} ROOK_CSI_ENABLE_CEPHFS: {{ .Values.csi.enableCephfsDriver | quote }} diff --git a/deploy/charts/rook-ceph/values.yaml b/deploy/charts/rook-ceph/values.yaml index 4d833fb28..cc8094da2 100644 --- a/deploy/charts/rook-ceph/values.yaml +++ b/deploy/charts/rook-ceph/values.yaml @@ -54,6 +54,9 @@ pspEnable: true # Set the priority class for the rook operator deployment if desired # priorityClassName: class +# If true, loop devices are allowed to be used for osds in test clusters +allowLoopDevices: false + ## Settings for whether to disable the drivers or other daemons if they are not ## needed csi: diff --git a/deploy/examples/operator-openshift.yaml b/deploy/examples/operator-openshift.yaml index a0e7ecffb..eaf98d1d6 100644 --- a/deploy/examples/operator-openshift.yaml +++ b/deploy/examples/operator-openshift.yaml @@ -110,6 +110,9 @@ data: # The logging level for the operator: ERROR | WARNING | INFO | DEBUG ROOK_LOG_LEVEL: "INFO" + # Allow using loop devices for osds in test clusters. + ROOK_CEPH_ALLOW_LOOP_DEVICES: "false" + # Enable the CSI driver. # To run the non-default version of the CSI driver, see the override-able image properties in operator.yaml ROOK_CSI_ENABLE_CEPHFS: "true" diff --git a/deploy/examples/operator.yaml b/deploy/examples/operator.yaml index 70d1a0c5a..fd13ead96 100644 --- a/deploy/examples/operator.yaml +++ b/deploy/examples/operator.yaml @@ -25,6 +25,9 @@ data: # The logging level for the operator: ERROR | WARNING | INFO | DEBUG ROOK_LOG_LEVEL: "INFO" + # Allow using loop devices for osds in test clusters. + ROOK_CEPH_ALLOW_LOOP_DEVICES: "false" + # Enable the CSI driver. # To run the non-default version of the CSI driver, see the override-able image properties in operator.yaml ROOK_CSI_ENABLE_CEPHFS: "true" diff --git a/pkg/clusterd/disk.go b/pkg/clusterd/disk.go index ed7d71104..d45d25a4d 100644 --- a/pkg/clusterd/disk.go +++ b/pkg/clusterd/disk.go @@ -19,6 +19,7 @@ package clusterd import ( "errors" "fmt" + "os" "path" "regexp" "strconv" @@ -41,7 +42,8 @@ func supportedDeviceType(device string) bool { device == sys.LVMType || device == sys.MultiPath || device == sys.PartType || - device == sys.LinearType + device == sys.LinearType || + (getAllowLoopDevices() && device == sys.LoopType) } // GetDeviceEmpty check whether a device is completely empty @@ -213,3 +215,7 @@ func PopulateDeviceUdevInfo(d string, executor exec.Executor, disk *sys.LocalDis return disk, nil } + +func getAllowLoopDevices() bool { + return os.Getenv("CEPH_VOLUME_ALLOW_LOOP_DEVICES") == "true" +} diff --git a/pkg/daemon/ceph/osd/daemon.go b/pkg/daemon/ceph/osd/daemon.go index feb5a7561..ecc906672 100644 --- a/pkg/daemon/ceph/osd/daemon.go +++ b/pkg/daemon/ceph/osd/daemon.go @@ -33,6 +33,7 @@ import ( "github.com/rook/rook/pkg/clusterd" "github.com/rook/rook/pkg/daemon/ceph/client" oposd "github.com/rook/rook/pkg/operator/ceph/cluster/osd" + cephver "github.com/rook/rook/pkg/operator/ceph/version" "github.com/rook/rook/pkg/util/sys" ) @@ -395,6 +396,13 @@ func getAvailableDevices(context *clusterd.Context, agent *OsdAgent) (*DeviceOsd } } + if device.Type == sys.LoopType { + if !agent.clusterInfo.CephVersion.IsAtLeast(cephver.CephVersion{Major: 17, Minor: 2, Extra: 4}) { + logger.Infof("partition %q is not picked because loop devices are not allowed on Ceph clusters older than v17.2.4", device.Name) + continue + } + } + // Check if the desired device is available // // We need to use the /dev path, provided by the NAME property from "lsblk --paths", @@ -449,6 +457,9 @@ func getAvailableDevices(context *clusterd.Context, agent *OsdAgent) (*DeviceOsd if device.Type == sys.LVMType { logger.Infof("logical volume %q is not picked by `useAllDevices: true`. please specify the exact device name (e.g. /dev/vg/lv) instead", device.Name) continue + } else if device.Type == sys.LoopType { + logger.Infof("loop device %q is not picked by `useAllDevices: true`. please specify the exact device name (e.g. /dev/loop0) instead", device.Name) + continue } deviceInfo = &DeviceOsdIDEntry{Data: unassignedOSDID, DeviceInfo: device} } else if len(desiredDevices) > 0 { @@ -460,6 +471,9 @@ func getAvailableDevices(context *clusterd.Context, agent *OsdAgent) (*DeviceOsd if device.Type == sys.LVMType { logger.Infof("logical volume %q is not picked by `deviceFilter`. please specify the exact device name (e.g. /dev/vg/lv) instead", device.Name) continue + } else if device.Type == sys.LoopType { + logger.Infof("loop device %q is not picked by `deviceFilter`. please specify the exact device name (e.g. /dev/loop0) instead", device.Name) + continue } matched, err = regexp.Match(desiredDevice.Name, []byte(device.Name)) if err != nil { @@ -474,6 +488,9 @@ func getAvailableDevices(context *clusterd.Context, agent *OsdAgent) (*DeviceOsd if device.Type == sys.LVMType { logger.Infof("logical volume %q is not picked by `devicePathFilter`. please specify the exact device name (e.g. /dev/vg/lv) instead", device.Name) continue + } else if device.Type == sys.LoopType { + logger.Infof("loop device %q is not picked by `devicePathFilter`. please specify the exact device name (e.g. /dev/loop0) instead", device.Name) + continue } pathnames := append(strings.Fields(device.DevLinks), filepath.Join("/dev", device.Name)) for _, pathname := range pathnames { diff --git a/pkg/daemon/ceph/osd/daemon_test.go b/pkg/daemon/ceph/osd/daemon_test.go index 5ab9aaa6a..bf6dcbd5e 100644 --- a/pkg/daemon/ceph/osd/daemon_test.go +++ b/pkg/daemon/ceph/osd/daemon_test.go @@ -379,6 +379,7 @@ NAME="sdb1" SIZE="30" TYPE="part" PKNAME="sdb"`, nil {Name: "sdt1", RealPath: "/dev/sdt1", Type: sys.PartType}, {Name: "sdv1", RealPath: "/dev/sdv1", Type: sys.PartType, Filesystem: "ext2"}, // has filesystem {Name: "dm-0", RealPath: "/dev/mapper/vg1-lv1", DevLinks: "/dev/mapper/vg1-lv1", Type: sys.LVMType}, // `useAllDevices` and `device{,Path}Filter` don't pick up logical volumes + {Name: "loop0", RealPath: "/dev/loop0", Type: sys.LoopType}, } version := cephver.Quincy @@ -522,6 +523,58 @@ NAME="sdb1" SIZE="30" TYPE="part" PKNAME="sdb"`, nil mapping, err = getAvailableDevices(context, agent) assert.Nil(t, err) assert.Equal(t, 0, len(mapping.Entries), mapping) + getOsdUUID = func(device *sys.LocalDisk) (string, error) { + return "", nil + } + + // loop device + os.Setenv("CEPH_VOLUME_ALLOW_LOOP_DEVICES", "true") + defer os.Unsetenv("CEPH_VOLUME_ALLOW_LOOP_DEVICES") + context.Devices = []*sys.LocalDisk{ + {Name: "loop0", RealPath: "/dev/loop0", Type: sys.LoopType}, + {Name: "loop1", RealPath: "/dev/loop1", Type: sys.LoopType}, + {Name: "sda", DevLinks: "/dev/disk/by-id/scsi-0123 /dev/disk/by-path/pci-0:1:2:3-scsi-1", RealPath: "/dev/sda"}, + } + + // loop device: Ceph version is too old + agent.pvcBacked = false + agent.devices = []DesiredDevice{{Name: "loop0"}} + mapping, err = getAvailableDevices(context, agent) + assert.Nil(t, err) + assert.Equal(t, 0, len(mapping.Entries)) + + // loop device: specify a loop device + agent.clusterInfo.CephVersion = cephver.CephVersion{ + Major: 17, + Minor: 2, + Extra: 4, + } + agent.pvcBacked = false + agent.devices = []DesiredDevice{{Name: "loop0"}} + mapping, err = getAvailableDevices(context, agent) + assert.Nil(t, err) + assert.Equal(t, 1, len(mapping.Entries)) + assert.Equal(t, -1, mapping.Entries["loop0"].Data) + + // loop device: useAllDevices + agent.devices = []DesiredDevice{{Name: "all"}} + mapping, err = getAvailableDevices(context, agent) + assert.Nil(t, err) + assert.Equal(t, 1, len(mapping.Entries)) + assert.Equal(t, -1, mapping.Entries["sda"].Data) + + // loop device: deviceFilter + agent.devices = []DesiredDevice{{Name: "loop0", IsFilter: true}} + mapping, err = getAvailableDevices(context, agent) + assert.Nil(t, err) + assert.Equal(t, 0, len(mapping.Entries)) + + // loop device: devicePathFilter + agent.devices = []DesiredDevice{{Name: "^/dev/loop.$", IsDevicePathFilter: true}} + mapping, err = getAvailableDevices(context, agent) + assert.Nil(t, err) + assert.Equal(t, 0, len(mapping.Entries)) + agent.clusterInfo.CephVersion = cephver.Quincy } func TestGetVolumeGroupName(t *testing.T) { diff --git a/pkg/operator/ceph/cluster/cleanup.go b/pkg/operator/ceph/cluster/cleanup.go index f08cde50f..12f101b56 100644 --- a/pkg/operator/ceph/cluster/cleanup.go +++ b/pkg/operator/ceph/cluster/cleanup.go @@ -121,6 +121,9 @@ func (c *ClusterController) cleanUpJobContainer(cluster *cephv1.CephCluster, mon {Name: sanitizeDataSource, Value: cluster.Spec.CleanupPolicy.SanitizeDisks.DataSource.String()}, {Name: sanitizeIteration, Value: strconv.Itoa(int(cluster.Spec.CleanupPolicy.SanitizeDisks.Iteration))}, }...) + if controller.LoopDevicesAllowed() { + envVars = append(envVars, v1.EnvVar{Name: "CEPH_VOLUME_ALLOW_LOOP_DEVICES", Value: "true"}) + } } // Run a UID 0 since ceph-volume does not support running non-root diff --git a/pkg/operator/ceph/cluster/osd/provision_spec.go b/pkg/operator/ceph/cluster/osd/provision_spec.go index df8c920e1..0f0783762 100644 --- a/pkg/operator/ceph/cluster/osd/provision_spec.go +++ b/pkg/operator/ceph/cluster/osd/provision_spec.go @@ -237,6 +237,10 @@ func (c *Cluster) provisionOSDContainer(osdProps osdProperties, copyBinariesMoun copyBinariesMount, }...) + if controller.LoopDevicesAllowed() { + envVars = append(envVars, v1.EnvVar{Name: "CEPH_VOLUME_ALLOW_LOOP_DEVICES", Value: "true"}) + } + // If the OSD runs on PVC if osdProps.onPVC() { volumeMounts = append(volumeMounts, getPvcOSDBridgeMount(osdProps.pvc.ClaimName)) diff --git a/pkg/operator/ceph/controller.go b/pkg/operator/ceph/controller.go index 861eef857..1e052c118 100644 --- a/pkg/operator/ceph/controller.go +++ b/pkg/operator/ceph/controller.go @@ -134,6 +134,8 @@ func (r *ReconcileConfig) reconcile(request reconcile.Request) (reconcile.Result return opcontroller.ImmediateRetryResult, err } + opcontroller.SetAllowLoopDevices(r.config.Parameters) + // Reconcile webhook secret // This is done in the predicate function diff --git a/pkg/operator/ceph/controller/controller_utils.go b/pkg/operator/ceph/controller/controller_utils.go index dcd096d3c..0230455aa 100644 --- a/pkg/operator/ceph/controller/controller_utils.go +++ b/pkg/operator/ceph/controller/controller_utils.go @@ -82,6 +82,9 @@ var ( // OperatorCephBaseImageVersion is the ceph version in the operator image OperatorCephBaseImageVersion string + + // loopDevicesAllowed indicates whether loop devices are allowed to be used + loopDevicesAllowed = false ) func DiscoveryDaemonEnabled(data map[string]string) bool { @@ -99,6 +102,20 @@ func SetCephCommandsTimeout(data map[string]string) { exec.CephCommandsTimeout = time.Duration(timeoutSeconds) * time.Second } +func SetAllowLoopDevices(data map[string]string) { + strLoopDevicesAllowed := k8sutil.GetValue(data, "ROOK_CEPH_ALLOW_LOOP_DEVICES", "false") + var err error + loopDevicesAllowed, err = strconv.ParseBool(strLoopDevicesAllowed) + if err != nil { + logger.Warningf("ROOK_CEPH_ALLOW_LOOP_DEVICES is set to an invalid value %v, set the default value false", strLoopDevicesAllowed) + loopDevicesAllowed = false + } +} + +func LoopDevicesAllowed() bool { + return loopDevicesAllowed +} + // canIgnoreHealthErrStatusInReconcile determines whether a status of HEALTH_ERR in the CephCluster can be ignored safely. func canIgnoreHealthErrStatusInReconcile(cephCluster cephv1.CephCluster, controllerName string) bool { // Get a list of all the keys causing the HEALTH_ERR status. diff --git a/pkg/operator/ceph/controller/controller_utils_test.go b/pkg/operator/ceph/controller/controller_utils_test.go index d88725510..1b4e01a9b 100644 --- a/pkg/operator/ceph/controller/controller_utils_test.go +++ b/pkg/operator/ceph/controller/controller_utils_test.go @@ -92,6 +92,20 @@ func TestSetCephCommandsTimeout(t *testing.T) { assert.Equal(t, 1*time.Second, exec.CephCommandsTimeout) } +func TestSetAllowLoopDevices(t *testing.T) { + SetAllowLoopDevices(map[string]string{}) + assert.False(t, LoopDevicesAllowed()) + + SetAllowLoopDevices(map[string]string{"ROOK_CEPH_ALLOW_LOOP_DEVICES": "foo"}) + assert.False(t, LoopDevicesAllowed()) + + SetAllowLoopDevices(map[string]string{"ROOK_CEPH_ALLOW_LOOP_DEVICES": "false"}) + assert.False(t, LoopDevicesAllowed()) + + SetAllowLoopDevices(map[string]string{"ROOK_CEPH_ALLOW_LOOP_DEVICES": "true"}) + assert.True(t, LoopDevicesAllowed()) +} + func TestIsReadyToReconcile(t *testing.T) { scheme := scheme.Scheme scheme.AddKnownTypes(cephv1.SchemeGroupVersion, &cephv1.CephCluster{}, &cephv1.CephClusterList{}) diff --git a/pkg/operator/ceph/controller_test.go b/pkg/operator/ceph/controller_test.go index 40115bc67..ed4485611 100644 --- a/pkg/operator/ceph/controller_test.go +++ b/pkg/operator/ceph/controller_test.go @@ -197,4 +197,50 @@ func TestOperatorController(t *testing.T) { assert.Equal(t, 1, len(ds.Items), ds) assert.Equal(t, "rook-discover", ds.Items[0].Name, ds) }) + + t.Run("success - cm set for allowing loop devices", func(t *testing.T) { + fakeClientSet := test.New(t, 1) + test.SetFakeKubernetesVersion(fakeClientSet, "v1.21.0") + c := &clusterd.Context{ + Clientset: fakeClientSet, + RookClientset: rookclient.NewSimpleClientset(), + } + + // Register operator types with the runtime scheme. + // s := scheme.Scheme + s := clientgoscheme.Scheme + // s.AddKnownTypes(cephv1.SchemeGroupVersion, &v1.ConfigMap{}) + + opConfigCM := &v1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: controller.OperatorSettingConfigMapName, + Namespace: namespace, + }, + Data: map[string]string{ + "ROOK_CEPH_ALLOW_LOOP_DEVICES": "true", + }, + } + + object := []runtime.Object{ + opConfigCM, + } + // Create a fake client to mock API calls. + cl := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(object...).Build() + + // Create a ReconcileCSI object with the scheme and fake client. + r := &ReconcileConfig{ + client: cl, + context: c, + config: controller.OperatorConfig{ + OperatorNamespace: namespace, + Image: "rook", + ServiceAccount: "foo", + }, + } + + res, err := r.Reconcile(ctx, req) + assert.NoError(t, err) + assert.False(t, res.Requeue) + assert.True(t, controller.LoopDevicesAllowed()) + }) } diff --git a/pkg/operator/discover/discover.go b/pkg/operator/discover/discover.go index 51626a34d..c5331012f 100644 --- a/pkg/operator/discover/discover.go +++ b/pkg/operator/discover/discover.go @@ -226,6 +226,11 @@ func (d *Discover) createDiscoverDaemonSet(ctx context.Context, namespace, disco ds.Spec.Template.ObjectMeta.Labels = podLabels } + if controller.LoopDevicesAllowed() { + ds.Spec.Template.Spec.Containers[0].Env = append(ds.Spec.Template.Spec.Containers[0].Env, + v1.EnvVar{Name: "CEPH_VOLUME_ALLOW_LOOP_DEVICES", Value: "true"}) + } + _, err = d.clientset.AppsV1().DaemonSets(namespace).Create(ctx, ds, metav1.CreateOptions{}) if err != nil { if !k8serrors.IsAlreadyExists(err) { diff --git a/pkg/util/sys/device.go b/pkg/util/sys/device.go index 9d7a2cdc9..06931a4f3 100644 --- a/pkg/util/sys/device.go +++ b/pkg/util/sys/device.go @@ -44,7 +44,9 @@ const ( MultiPath = "mpath" // LinearType is a linear type LinearType = "linear" - sgdiskCmd = "sgdisk" + // LoopType is a loop device type + LoopType = "loop" + sgdiskCmd = "sgdisk" // CephLVPrefix is the prefix of a LV owned by ceph-volume CephLVPrefix = "ceph--" // DeviceMapperPrefix is the prefix of a LV from the device mapper interface diff --git a/tests/scripts/github-action-helper.sh b/tests/scripts/github-action-helper.sh index 8351dd8f8..242caab18 100755 --- a/tests/scripts/github-action-helper.sh +++ b/tests/scripts/github-action-helper.sh @@ -39,6 +39,23 @@ function print_k8s_cluster_status() { kubectl get pods -n kube-system } +function prepare_loop_devices() { + if [ $# -ne 1 ]; then + echo "usage: $0 loop_deivce_count" + exit 1 + fi + OSD_COUNT=$1 + if [ $OSD_COUNT -le 0 ]; then + echo "Invalid OSD_COUNT $OSD_COUNT. OSD_COUNT must be larger than 0." + exit 1 + fi + for i in $(seq 1 $OSD_COUNT); do + sudo dd if=/dev/zero of=~/data${i}.img bs=1M seek=6144 count=0 + sudo losetup /dev/loop${i} ~/data${i}.img + done + sudo lsblk +} + function use_local_disk() { BLOCK_DATA_PART=${BLOCK}1 sudo apt purge snapd -y @@ -204,6 +221,10 @@ function deploy_manifest_with_local_build() { if [[ "$USE_LOCAL_BUILD" != "false" ]]; then sed -i "s|image: rook/ceph:.*|image: rook/ceph:local-build|g" $1 fi + if [[ "$ALLOW_LOOP_DEVICES" = "true" ]]; then + sed -i "s|ROOK_CEPH_ALLOW_LOOP_DEVICES: \"false\"|ROOK_CEPH_ALLOW_LOOP_DEVICES: \"true\"|g" $1 + fi + sed -i "s|ROOK_LOG_LEVEL:.*|ROOK_LOG_LEVEL: DEBUG|g" "$1" kubectl create -f $1 } @@ -230,6 +251,9 @@ function deploy_cluster() { sed -i "s|#deviceFilter:|deviceFilter: ${BLOCK/\/dev\//}\n config:\n encryptedDevice: \"true\"|g" cluster-test.yaml elif [ "$1" = "lvm" ]; then sed -i "s|#deviceFilter:|devices:\n - name: \"/dev/test-rook-vg/test-rook-lv\"|g" cluster-test.yaml + elif [ "$1" = "loop" ]; then + # add both /dev/sdX1 and loop device to test them at the same time + sed -i "s|#deviceFilter:|devices:\n - name: \"${BLOCK}\"\n - name: \"/dev/loop1\"|g" cluster-test.yaml else echo "invalid argument: $*" >&2 exit 1 diff --git a/tests/scripts/loopDevicePV.sh b/tests/scripts/loopDevicePV.sh new file mode 100755 index 000000000..41d8861b4 --- /dev/null +++ b/tests/scripts/loopDevicePV.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +# Copyright 2021 The Rook Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -ex + +############# +# VARIABLES # +############# +osd_count=$1 +sudo lsblk + +############# +# FUNCTIONS # +############# + +function add_loop_dev_pvc() { + local osd_count=$1 + local storage=6Gi + + for osd in $(seq 1 "$osd_count"); do + path=/dev/loop${osd} + + cat <