osd: add a new devicetype label for osds

currently device class and device type
labels were clubbed with eachother
create a seperate label, as these two labels
can be seperate

Signed-off-by: parth-gr <partharora1010@gmail.com>
(cherry picked from commit 01456e8683)
This commit is contained in:
parth-gr authored and Mergify committed 2024-12-05 23:21:39 +00:00
1 parent 2273c40647
commit e0af3d4bee
6 files changed
+37 -15

No files matched your search

+1 -1
View File
@@ -94,5 +94,5 @@ func (d *DesiredDevice) UpdateDeviceClass(agent *OsdAgent, device *sys.LocalDisk
}
}
d.DeviceClass = sys.GetDiskDeviceClass(device)
d.DeviceClass = sys.GetDiskDeviceType(device)
}
+7 -9
View File
@@ -1158,17 +1158,15 @@ func GetCephVolumeRawOSDs(context *clusterd.Context, clusterInfo *client.Cluster
if !skipDeviceClass {
diskInfo, err := clusterd.PopulateDeviceInfo(blockPath, context.Executor)
crushDeviceClass := os.Getenv(oposd.CrushDeviceClassVarName)
if crushDeviceClass != "" {
osd.DeviceClass = crushDeviceClass
if err != nil {
return nil, errors.Wrapf(err, "failed to get device info for %q", blockPath)
}
deviceType := sys.GetDiskDeviceType(diskInfo)
osd.DeviceType = deviceType
logger.Infof("setting device type %q for device %q", osd.DeviceType, diskInfo.Name)
if osd.DeviceClass == "" {
if err != nil {
return nil, errors.Wrapf(err, "failed to get device info for %q", blockPath)
}
osd.DeviceClass = sys.GetDiskDeviceClass(diskInfo)
}
crushDeviceClass := sys.GetDiskDeviceClass(oposd.CrushDeviceClassVarName, deviceType)
osd.DeviceClass = crushDeviceClass
logger.Infof("setting device class %q for device %q", osd.DeviceClass, diskInfo.Name)
}
+3
View File
@@ -60,6 +60,9 @@ func (c *Cluster) getOSDLabels(osd OSDInfo, failureDomainValue string, portable
labels[portableKey] = strconv.FormatBool(portable)
labels[deviceClass] = osd.DeviceClass
labels[osdStore] = osd.Store
if osd.DeviceType != "" {
labels[deviceType] = osd.DeviceType
}
for k, v := range getOSDTopologyLocationLabels(osd.Location) {
labels[k] = v
+2
View File
@@ -73,6 +73,7 @@ const (
bluestorePVCData = "data"
deviceClass = "device-class"
osdStore = "osd-store"
deviceType = "device-type"
)
// Cluster keeps track of the OSDs
@@ -121,6 +122,7 @@ type OSDInfo struct {
ExportService bool `json:"exportService"`
NodeName string `json:"nodeName"`
PVCName string `json:"pvcName"`
DeviceType string `json:"device-type"`
}
// OrchestrationStatus represents the status of an OSD orchestration
+11 -1
View File
@@ -19,6 +19,7 @@ package sys
import (
"encoding/json"
"fmt"
"os"
osexec "os/exec"
"strconv"
"strings"
@@ -279,7 +280,7 @@ func GetDiskUUID(device string, executor exec.Executor) (string, error) {
return parseUUID(device, output)
}
func GetDiskDeviceClass(disk *LocalDisk) string {
func GetDiskDeviceType(disk *LocalDisk) string {
if disk.Rotational {
return "hdd"
}
@@ -289,6 +290,15 @@ func GetDiskDeviceClass(disk *LocalDisk) string {
return "ssd"
}
func GetDiskDeviceClass(crushDeviceClassVarName, deviceType string) string {
crushDeviceClass := os.Getenv(crushDeviceClassVarName)
if crushDeviceClass != "" {
return crushDeviceClass
} else {
return deviceType
}
}
// CheckIfDeviceAvailable checks if a device is available for consumption. The caller
// needs to decide based on the return values whether it is available.
func CheckIfDeviceAvailable(executor exec.Executor, devicePath string, pvcBacked bool) (bool, string, error) {
+13 -4
View File
@@ -197,12 +197,21 @@ func TestListDevicesChildListDevicesChild(t *testing.T) {
assert.Equal(t, 3, len(child))
}
func TestGetDiskDeviceClass(t *testing.T) {
func TestGetDiskDeviceType(t *testing.T) {
d := &LocalDisk{}
assert.Equal(t, "ssd", GetDiskDeviceClass(d))
assert.Equal(t, "ssd", GetDiskDeviceType(d))
d.Rotational = true
assert.Equal(t, "hdd", GetDiskDeviceClass(d))
assert.Equal(t, "hdd", GetDiskDeviceType(d))
d.Rotational = false
d.RealPath = "nvme"
assert.Equal(t, "nvme", GetDiskDeviceClass(d))
assert.Equal(t, "nvme", GetDiskDeviceType(d))
}
func TestGetDiskDeviceClass(t *testing.T) {
t.Setenv("ROOK_OSD_CRUSH_DEVICE_CLASS", "test")
assert.Equal(t, "test", GetDiskDeviceClass("ROOK_OSD_CRUSH_DEVICE_CLASS", "hdd"))
t.Setenv("ROOK_OSD_CRUSH_DEVICE_CLASS", "test1")
assert.Equal(t, "test1", GetDiskDeviceClass("ROOK_OSD_CRUSH_DEVICE_CLASS", "hdd"))
t.Setenv("ROOK_OSD_CRUSH_DEVICE_CLASS", "")
assert.Equal(t, "nvme", GetDiskDeviceClass("ROOK_OSD_CRUSH_DEVICE_CLASS", "nvme"))
}