From 281ebc0408a72c24c537ebab9007f356b5a0d436 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Mon, 17 Jun 2024 12:58:33 +1000 Subject: [PATCH 1/3] filters: Set pathFilterName correctly Signed-off-by: Tim Serong (cherry picked from commit debd24256f14964abe9f1cd2e3644b197923f472) --- pkg/filter/path_filter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/filter/path_filter.go b/pkg/filter/path_filter.go index f0b5f9c0..c9f19efe 100644 --- a/pkg/filter/path_filter.go +++ b/pkg/filter/path_filter.go @@ -30,7 +30,7 @@ func RegisterPathFilter(filters ...string) *Filter { } } return &Filter{ - Name: partTypeFilterName, + Name: pathFilterName, PartFilter: f, DiskFilter: &diskPathFilter{mountPaths: f.mountPaths}, } From 38c52186a45bea63d47c631f01154b6653faf426 Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Mon, 17 Jun 2024 13:03:37 +1000 Subject: [PATCH 2/3] build: explain how version variables are set Signed-off-by: Tim Serong (cherry picked from commit a62a1771a61c6cfb25f93bc3e2de828cb213b7ef) --- pkg/version/version.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/version/version.go b/pkg/version/version.go index 3482d080..e5022256 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -2,6 +2,7 @@ package version import "fmt" +// These values are set via linker flags in scripts/build var ( Version = "v0.0.0-dev" GitCommit = "HEAD" From fc27fb66fe10478a1c37fddfbfe71597e71bce4c Mon Sep 17 00:00:00 2001 From: Tim Serong Date: Mon, 17 Jun 2024 18:19:22 +1000 Subject: [PATCH 3/3] README: add a little more detail, reword a few things Signed-off-by: Tim Serong (cherry picked from commit 1cc84e893d9c2641588b5d247af81de9a7b13a15) --- README.md | 58 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 10eb66b6..c0a3aaa0 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,31 @@ node-disk-manager ======== -disk manager help to manage host disks, implementing disk partition and file system formatting. +Node Disk Manager helps to manage host disks, implementing disk partitioning and file system formatting. ## Building `make` +This will build both amd64 and arm64 binaries, plus a container image +which will be named something like `harvester/node-disk-manager:dev`. + +To build a container image and push it to your own repo on dockerhub, do this: + +```sh +export REPO="your dockerhub username" +make +docker push $REPO/node-disk-manager:dev +``` + ## Running -`./bin/node-disk-manager` +The binaries for each architecture can be run directly for development or testing purposes: + +```sh +./bin/node-disk-manager-amd64 --node-name "$(hostname -s)" +./bin/node-disk-manager-arm64 --node-name "$(hostname -s)" +``` ## Features @@ -39,45 +55,47 @@ separately later. First, let us learn about the custom resource for NDM: ### `blockdevices` Custom Resource A `blockdevice` is a Kubernetes custom resource (CR) that represents a -block device on a node. `blockdevice` CR records several lower-level block -device information from the operating system, for example, file system status, -mount point, and UUIDs. These details are all stored in `status.deviceStatus`. +block device on a node. The `blockdevice` CR records lower-level block device +information from the operating system, for example, file system status, mount +point, and UUIDs. These details are all stored in `status.deviceStatus`. The name of a `blockdevice` is a global identifier across nodes within the whole cluster. At this moment, we recommend disk you want to provision to have at least WWN on it. It helps the system to globally identify the `blockdevice` -resource and link to real block device of the operating system. +resource and link to real block device of the operating system. For disks with +a WWN, the global identifier is a hash of the concatenation of the node name, +with the disk's WWN, Vendor, Model and Serial Number. -Besides its `name` field, the most important fields you need to know is -`spec.fileSystem.provisioned` and `spec.fileSystem.forceFormatted`. The format +Besides its `name` field, the most important fields you need to know are +`spec.fileSystem.provisioned` and `spec.fileSystem.forceFormatted`. The former implies that a user expects the block device to be provisioned as Longhorn disk for further usage. And the latter just indicates that NDM would perform a disk formatting if not yet done before. ### Disk Discovery -As a daemonset workload, each NDM instance takes charge of disk on its own node. +As a daemonset workload, each NDM instance takes charge of disks on its own node. There are two components collecting the information of disks on the node, as -well as creating, updating, or deleting corresponding blockdevice CR. +well as creating, updating, or deleting corresponding blockdevice CRs. The first is `scanner`. It scans all supported block devices on the system and -creates a new one if not exists, or deletes old one if is already removed from -the system. For block devices that need to update, it simply enqueue the -`blockdevice` CR to let blockdevice controller handle the update path to prevent -any possible race condition. Scanner also periodically scans the system to inform -the controller to update info if needed. +creates a new `blockdevice` CR if one does not exist, or deletes the old CR if +is already removed from the system. For block devices that need to be updated, it +simply enqueues the `blockdevice` CR to let blockdevice controller handle the +update path to prevent any possible race condition. Scanner also periodically +scans the system to inform the controller to update info if needed. The other key component is `udev`, which utilizes Linux's dynamic device management mechanism. `udev`, as a supplement of scanner, mostly behaves the same as scanner, but instantly for responding to hot-plugged devices. There is a module `filter`. It comprises several filter functions, which -get their own predicates to determine which block device should be collected by +have their own predicates to determine which block device should be collected by scanner and udev. ### Disk Provisioning -The controller of NDM listens for changes of `blockdevice` CR and perform +The controller of NDM listens for changes of `blockdevice` CR and performs corresponding actions, namely - Format disk @@ -85,7 +103,7 @@ corresponding actions, namely - Provision/Unprovision disk to/from Longhorn - Update device status details -Which actual action to perform is determines by the combination of +Which actual action to perform are determined by the combination of `spec.fileSystem`, device formatting and mounting status, and `status.provisionPhase`. The last one indicates whether the block device is currently used by Longhorn. @@ -113,8 +131,8 @@ Here we give the Sample XML for `libvirt` to create a SCSI device with `WWN`. ``` -**NOTE**: If we create w/o WWN, NDM will use filesystem UUID as a unique identifier. -That has some limitations. For example, the UUID will be missed if the filesystem metadata is broken. +**NOTE**: When disks don't have a WWN, NDM will use filesystem UUID as a unique identifier. +That has some limitations. For example, the UUID will be missing if the filesystem metadata is broken. ## License Copyright (c) 2022 [Rancher Labs, Inc.](http://rancher.com)