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 <shinya-hayashi@cybozu.co.jp>
(cherry picked from commit 05875a3f4f)
This commit is contained in:
Shinya Hayashi authored and Mergify committed 2022-11-10 18:31:43 +00:00
1 parent 8787dab0a1
commit 13b63c4a08
19 files changed
+294 -6

No files matched your search

+17 -4
View File
@@ -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()
@@ -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 | `<none>` |
| `discover.toleration` | Toleration for the discover pods | `<none>` |
| `discover.tolerationKey` | The specific key of the taint to tolerate | `<none>` |
@@ -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 }}
+3
View File
@@ -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:
+3
View File
@@ -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"
+3
View File
@@ -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"
+7 -1
View File
@@ -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"
}
+17
View File
@@ -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 {
+53
View File
@@ -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) {
+3
View File
@@ -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
@@ -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))
+2
View File
@@ -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
@@ -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.
@@ -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{})
+46
View File
@@ -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())
})
}
+5
View File
@@ -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) {
+3 -1
View File
@@ -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
+24
View File
@@ -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
+71
View File
@@ -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 <<eof | kubectl apply -f -
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-vol-loop-dev$osd
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: "$storage"
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
volumeMode: Block
local:
path: "$path"
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: rook.io/has-disk
operator: In
values:
- "true"
eof
done
}
########
# MAIN #
########
add_loop_dev_pvc "$osd_count"
kubectl get pv -o wide