openebs-archive / node-disk-manager

Kubernetes Storage Device Management
https://openebs.io/docs
Apache License 2.0
182 stars 113 forks source link

feat(path-filter): Filter blockdevice using custom udev rules #670

Closed Ab-hishek closed 2 years ago

Ab-hishek commented 2 years ago

Signed-off-by: Abhishek Agarwal abhishek.agarwal@mayadata.io

Why is this PR required? What issue does it fix?: This PR fixes the issue - https://github.com/openebs/openebs/issues/3491

What this PR does?: This PR adds extra dev links(apart from by-id and by-path) info which we get from theudev` probe. This are useful to filter out bds when a disk is configured with some custom udev rules and uses those rules inside the path filter config of ndm.

Does this PR require any upgrade changes?: No

If the changes in this PR are manually verified, list down the scenarios covered::

  1. Added custom udev rules for a disk: KERNEL=="sdb1",SYMLINK+="openebs_storage_02"
  2. Relead the udev db using the command: udevadm control --reload
  3. The new symlink is available in the udev output now:
    P: /devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0/host3/target3:0:0/3:0:0:0/block/sdb/sdb1
    N: sdb1
    L: 0
    S: disk/by-uuid/E48D-9C94
    S: disk/by-path/pci-0000:00:14.0-usb-0:4:1.0-scsi-0:0:0:0-part1
    S: disk/by-label/ABHISHEK
    S: disk/by-id/usb-JetFlash_Transcend_8GB_OWXSZQ7L-0:0-part1
    S: openebs_storage_02
    S: disk/by-partuuid/02a28704-01
    E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0/host3/target3:0:0/3:0:0:0/block/sdb/sdb1
    E: DEVNAME=/dev/sdb1
    E: DEVTYPE=partition
    E: DEVLINKS=/dev/disk/by-uuid/E48D-9C94 /dev/disk/by-path/pci-0000:00:14.0-usb-0:4:1.0-scsi-0:0:0:0-part1 /dev/disk/by-label/ABHISHEK /dev/disk/by-id/usb-JetFlash_Transcend_8GB_OWXSZQ7L-0:0-part1 /dev/openebs_storage_02 /dev/disk/by-partuuid/02a28704-01
    E: TAGS=:systemd:
  4. Install ndm operator
  5. Update the ndm config: a. Exclude the disk with symlink: /dev/openebs_storage_02 using exclude path filter:
    - key: path-filter
      name: path filter
      state: true
      include: ""
      exclude: "/dev/loop,/dev/openebs_storage_02,/dev/fd0,/dev/sr0,/dev/ram,/dev/md,/dev/dm-,/dev/rbd,/dev/zd"

    OUTPUT: Listing bds with kubectl get bd -n openebs doesn't list the above disk. b. Include the disk with symlink: /dev/openebs_storage_02 using include path filter:

    - key: path-filter
      name: path filter
      state: true
      include: "/dev/openebs_storage_02"
      exclude: "/dev/loop,/dev/fd0,/dev/sr0,/dev/ram,/dev/md,/dev/dm-,/dev/rbd,/dev/zd"

    OUTPUT: Listing bds with kubectl get bd -n openebs does list the above disk.

  6. The bds are listed is it should have been:
     abhishek@abhishek-Mayadata:~$ kubectl get bd -n openebs
     NAME                                           NODENAME            SIZE         CLAIMSTATE   STATUS   AGE
     blockdevice-0db0a0b21ddbc52266b551d2d1c53791   abhishek-mayadata   7812939776   Unclaimed    Active   4s
     blockdevice-14065e0e32469367655092a3333cfe99   abhishek-mayadata   1024         Unclaimed    Active   102s
     blockdevice-2345c8576f192616c18b8f9f19f2497e   abhishek-mayadata   536870912    Unclaimed    Active   102s

    blockdevice-0db0a0b21ddbc52266b551d2d1c53791 abhishek-mayadata 7812939776 Unclaimed Active 4s is the one having the custom udev rule

Any additional information for your reviewer? : Mention if this PR is part of any design or a continuation of previous PRs

Checklist:

codecov-commenter commented 2 years ago

Codecov Report

Merging #670 (305ef99) into develop (9f40337) will increase coverage by 0.50%. The diff coverage is 71.42%.

@@             Coverage Diff             @@
##           develop     #670      +/-   ##
===========================================
+ Coverage    44.83%   45.33%   +0.50%     
===========================================
  Files           79       79              
  Lines         3970     3990      +20     
===========================================
+ Hits          1780     1809      +29     
+ Misses        2023     2012      -11     
- Partials       167      169       +2     
Impacted Files Coverage Δ
cmd/ndm_daemonset/filter/pathfilter.go 69.38% <50.00%> (-7.54%) :arrow_down:
cmd/ndm_daemonset/probe/udevprobe.go 50.00% <100.00%> (+3.35%) :arrow_up:
pkg/udev/common.go 88.05% <100.00%> (+0.75%) :arrow_up:
pkg/udev/mockdata.go 67.12% <100.00%> (+0.45%) :arrow_up:
pkg/udev/udev.go 90.00% <0.00%> (ø)
pkg/udev/device.go 100.00% <0.00%> (ø)
pkg/udev/monitor.go 80.00% <0.00%> (ø)
pkg/udev/enumerate.go 58.33% <0.00%> (ø)
pkg/udev/listentry.go 0.00% <0.00%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2936ea7...305ef99. Read the comment docs.

pawanpraka1 commented 2 years ago

@akhilerm could you review this PR?