From bbedf62c46326bb081d98394cd9f812a048c21c1 Mon Sep 17 00:00:00 2001 From: Vicente Cheng Date: Thu, 30 Nov 2023 15:04:38 +0800 Subject: [PATCH] controller: add disk tags to BlockDeviceSpec Then, we can add disk tags with provision to longhorn Signed-off-by: Vicente Cheng --- manifests/crds/harvesterhci.io_blockdevices.yaml | 3 +++ pkg/apis/harvesterhci.io/v1beta1/types.go | 3 +++ pkg/controller/blockdevice/controller.go | 9 +++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/manifests/crds/harvesterhci.io_blockdevices.yaml b/manifests/crds/harvesterhci.io_blockdevices.yaml index 015a6167..00cc0dfd 100644 --- a/manifests/crds/harvesterhci.io_blockdevices.yaml +++ b/manifests/crds/harvesterhci.io_blockdevices.yaml @@ -84,6 +84,9 @@ spec: nodeName: description: name of the node to which the block device is attached type: string + tags: + description: a string with for device tag for provisioner, e.g. "default,small,ssd" + type: string required: - devPath - fileSystem diff --git a/pkg/apis/harvesterhci.io/v1beta1/types.go b/pkg/apis/harvesterhci.io/v1beta1/types.go index 1aead78c..b912673e 100644 --- a/pkg/apis/harvesterhci.io/v1beta1/types.go +++ b/pkg/apis/harvesterhci.io/v1beta1/types.go @@ -39,6 +39,9 @@ type BlockDeviceSpec struct { DevPath string `json:"devPath"` FileSystem *FilesystemInfo `json:"fileSystem"` + + // a string with for device tag for provisioner, e.g. "default,small,ssd" + Tags string `json:"tags,omitempty"` } type BlockDeviceStatus struct { diff --git a/pkg/controller/blockdevice/controller.go b/pkg/controller/blockdevice/controller.go index a29c3dce..3ba6361a 100644 --- a/pkg/controller/blockdevice/controller.go +++ b/pkg/controller/blockdevice/controller.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "reflect" + "strings" "time" gocommon "github.com/harvester/go-common" @@ -365,20 +366,24 @@ func (c *Controller) provisionDeviceToNode(device *diskv1.BlockDevice) error { return err } + tags := make([]string, 0) + if device.Spec.Tags != "" { + tags = strings.Split(device.Spec.Tags, ",") + } nodeCpy := node.DeepCopy() diskSpec := longhornv1.DiskSpec{ Path: extraDiskMountPoint(device), AllowScheduling: true, EvictionRequested: false, StorageReserved: 0, - Tags: []string{}, + Tags: tags, } needUpdated := false if disk, found := node.Spec.Disks[device.Name]; found { /* we should respect the disk Tags from LH */ logrus.Debugf("Previous disk tags on LH: %+v, we should respect it.", disk.Tags) - diskSpec.Tags = disk.Tags + diskSpec.Tags = append(diskSpec.Tags, disk.Tags...) needUpdated = reflect.DeepEqual(disk, diskSpec) } // **NOTE** we do the `DiskAddedToNode` check here if we failed to update the device.