From 910fe6f980a3522ee43d3a805b70d41ab2e97d13 Mon Sep 17 00:00:00 2001 From: Nizamudeen Date: Tue, 29 Oct 2019 18:31:21 +0530 Subject: [PATCH] ceph: make the udevfilter into configurable Added default regex values. Created an environment variable and using that variable the user can give custom regex values Updated the PendingReleaseNotes.md Signed-off-by: Nizamudeen --- PendingReleaseNotes.md | 3 +++ cluster/charts/rook-ceph/values.yaml | 3 +++ .../kubernetes/ceph/operator-openshift.yaml | 7 +++++++ cluster/examples/kubernetes/ceph/operator.yaml | 8 ++++++++ pkg/daemon/discover/discover.go | 18 +++++++++++++++++- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/PendingReleaseNotes.md b/PendingReleaseNotes.md index 7f39aee20..1c133ca69 100644 --- a/PendingReleaseNotes.md +++ b/PendingReleaseNotes.md @@ -26,6 +26,9 @@ - nfs: [samples](Documentation/ceph-nfs-crd.md#samples) - When the operator is upgraded, the mgr and osd (not running on PVC) won't be restarted if the Rook binary version changes - Rook is now able to create and manage Ceph clients [client crd](Documentation/ceph-client-crd.html). +- Device Filtering made configurable for the user by adding an environment variable, and also by keeping the default filters intact + - A new environment variable `DISCOVER_DAEMON_UDEV_BLACKLIST` is added through which the user can blacklist the devices + - If no device is specified, the default values will be used to blacklist the devices ### EdgeFS diff --git a/cluster/charts/rook-ceph/values.yaml b/cluster/charts/rook-ceph/values.yaml index c0c3d38dd..83a19199a 100644 --- a/cluster/charts/rook-ceph/values.yaml +++ b/cluster/charts/rook-ceph/values.yaml @@ -138,6 +138,9 @@ hostpathRequiresPrivileged: false # Disable automatic orchestration when new devices are discovered. disableDeviceHotplug: false +# Blacklist certain disks according to the regex provided. +discoverDaemonUdev: + # imagePullSecrets option allow to pull docker images from private docker registry. Option will be passed to all service accounts. # imagePullSecrets: # - name: my-registry-secret diff --git a/cluster/examples/kubernetes/ceph/operator-openshift.yaml b/cluster/examples/kubernetes/ceph/operator-openshift.yaml index b0f53e471..36f6f9052 100644 --- a/cluster/examples/kubernetes/ceph/operator-openshift.yaml +++ b/cluster/examples/kubernetes/ceph/operator-openshift.yaml @@ -202,6 +202,13 @@ spec: # Disable automatic orchestration when new devices are discovered - name: ROOK_DISABLE_DEVICE_HOTPLUG value: "false" + # Provide customised regex as the values using comma. For eg. regex for rbd based volume, value will be like "(?i)rbd[0-9]+". + # In case of more than one regex, use comma to seperate between them. + # Default regex will be "(?i)dm-[0-9]+,(?i)rbd[0-9]+,(?i)nbd[0-9]+" + # add regex expression after putting a comma to blacklist a disk + # If value is empty, the default regex will be used. + - name: DISCOVER_DAEMON_UDEV_BLACKLIST + value: "(?i)dm-[0-9]+,(?i)rbd[0-9]+,(?i)nbd[0-9]+" # Whether to enable the flex driver. By default it is enabled and is fully supported, but will be deprecated in some future release # in favor of the CSI driver. diff --git a/cluster/examples/kubernetes/ceph/operator.yaml b/cluster/examples/kubernetes/ceph/operator.yaml index 3087c3225..e710b7bb4 100644 --- a/cluster/examples/kubernetes/ceph/operator.yaml +++ b/cluster/examples/kubernetes/ceph/operator.yaml @@ -155,6 +155,14 @@ spec: - name: ROOK_DISABLE_DEVICE_HOTPLUG value: "false" + # Provide customised regex as the values using comma. For eg. regex for rbd based volume, value will be like "(?i)rbd[0-9]+". + # In case of more than one regex, use comma to seperate between them. + # Default regex will be "(?i)dm-[0-9]+,(?i)rbd[0-9]+,(?i)nbd[0-9]+" + # Add regex expression after putting a comma to blacklist a disk + # If value is empty, the default regex will be used. + - name: DISCOVER_DAEMON_UDEV_BLACKLIST + value: "(?i)dm-[0-9]+,(?i)rbd[0-9]+,(?i)nbd[0-9]+" + # Whether to enable the flex driver. By default it is enabled and is fully supported, but will be deprecated in some future release # in favor of the CSI driver. - name: ROOK_ENABLE_FLEX_DRIVER diff --git a/pkg/daemon/discover/discover.go b/pkg/daemon/discover/discover.go index fab0b5da5..64225684f 100644 --- a/pkg/daemon/discover/discover.go +++ b/pkg/daemon/discover/discover.go @@ -40,6 +40,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +const ( + discoverDaemonUdev = "DISCOVER_DAEMON_UDEV_BLACKLIST" +) + var ( logger = capnslog.NewPackageLogger("github.com/rook/rook", "rook-discover") AppName = "rook-discover" @@ -176,13 +180,25 @@ func rawUdevBlockMonitor(c chan string, matches, exclusions []string) { // only one event is emitted per period in order to deal with flapping. func udevBlockMonitor(c chan string, period time.Duration) { defer close(c) + var udevFilter []string // return any add or remove events, but none that match device mapper // events. string matching is case-insensitve events := make(chan string) + + // get discoverDaemonUdevBlacklist from the enviornment variable + // if user doesnt provide any regex; generate the default regex + // else use the regex provided by user + discoverUdev := os.Getenv(discoverDaemonUdev) + if discoverUdev == "" { + discoverUdev = "(?i)dm-[0-9]+,(?i)rbd[0-9]+,(?i)nbd[0-9]+" + } + udevFilter = strings.Split(discoverUdev, ",") + logger.Infof("using the regular expressions %q", udevFilter) + go rawUdevBlockMonitor(events, []string{"(?i)add", "(?i)remove"}, - []string{"(?i)dm-[0-9]+", "(?i)rbd[0-9]+", "(?i)nbd[0-9]+"}) + udevFilter) for { event, ok := <-events