Skip to content

Commit

Permalink
controller: add disk tags to BlockDeviceSpec
Browse files Browse the repository at this point in the history
    Then, we can add disk tags with provision to longhorn

Signed-off-by: Vicente Cheng <[email protected]>
  • Loading branch information
Vicente-Cheng committed Nov 30, 2023
1 parent ccd46e8 commit bbedf62
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions manifests/crds/harvesterhci.io_blockdevices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/harvesterhci.io/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions pkg/controller/blockdevice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"reflect"
"strings"
"time"

gocommon "github.com/harvester/go-common"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit bbedf62

Please sign in to comment.