-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add longhorn v2 provisioner #82
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ import ( | |
|
||
const ( | ||
blockDeviceHandlerName = "harvester-block-device-handler" | ||
defaultProvisioner = "longhornv1" | ||
) | ||
|
||
// semaphore is a simple semaphore implementation in channel | ||
|
@@ -212,12 +213,16 @@ func (c *Controller) OnBlockDeviceChange(_ string, device *diskv1.BlockDevice) ( | |
if devPath == "" { | ||
return nil, fmt.Errorf("failed to resolve persistent dev path for block device %s", device.Name) | ||
} | ||
if device.Spec.Provisioner == "" { | ||
deviceCpy.Spec.Provisioner = defaultProvisioner | ||
} | ||
|
||
filesystem := c.BlockInfo.GetFileSystemInfoByDevPath(devPath) | ||
devPathStatus := convertFSInfoToString(filesystem) | ||
logrus.Debugf("Get filesystem info from device %s, %s", devPath, devPathStatus) | ||
|
||
needFormat := deviceCpy.Spec.FileSystem.ForceFormatted && (deviceCpy.Status.DeviceStatus.FileSystem.Corrupted || deviceCpy.Status.DeviceStatus.FileSystem.LastFormattedAt == nil) | ||
if needFormat { | ||
if deviceCpy.Spec.Provisioner == defaultProvisioner && needFormat { | ||
logrus.Infof("Prepare to force format device %s", device.Name) | ||
err := c.forceFormat(deviceCpy, devPath, filesystem) | ||
if err != nil { | ||
|
@@ -233,7 +238,8 @@ func (c *Controller) OnBlockDeviceChange(_ string, device *diskv1.BlockDevice) ( | |
return device, err | ||
} | ||
|
||
if needMountUpdate := needUpdateMountPoint(deviceCpy, filesystem); needMountUpdate != NeedMountUpdateNoOp { | ||
needMountUpdate := needUpdateMountPoint(deviceCpy, filesystem) | ||
if deviceCpy.Spec.Provisioner == defaultProvisioner && needMountUpdate != NeedMountUpdateNoOp { | ||
err := c.updateDeviceMount(deviceCpy, devPath, filesystem, needMountUpdate) | ||
if err != nil { | ||
err := fmt.Errorf("failed to update device mount %s: %s", device.Name, err.Error()) | ||
|
@@ -461,13 +467,14 @@ func (c *Controller) provisionDeviceToNode(device *diskv1.BlockDevice) error { | |
} | ||
|
||
nodeCpy := node.DeepCopy() | ||
diskSpec := longhornv1.DiskSpec{ | ||
Path: extraDiskMountPoint(device), | ||
AllowScheduling: true, | ||
EvictionRequested: false, | ||
StorageReserved: 0, | ||
Tags: device.Spec.Tags, | ||
|
||
diskSpec := generateDiskSpec(device.Spec.Provisioner) | ||
if device.Spec.Provisioner == defaultProvisioner { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: suggest handling each case explicitly to prevent using |
||
diskSpec.Path = extraDiskMountPoint(device) | ||
} else { | ||
diskSpec.Path = device.Status.DeviceStatus.DevPath | ||
} | ||
diskSpec.Tags = device.Spec.Tags | ||
|
||
updated := false | ||
if disk, found := node.Spec.Disks[device.Name]; found { | ||
|
@@ -803,12 +810,16 @@ func convertFSInfoToString(fsInfo *block.FileSystemInfo) string { | |
return fmt.Sprintf("mountpoint: %s, fsType: %s", fsInfo.MountPoint, fsInfo.Type) | ||
} | ||
|
||
func removeUnNeeded[T string | int](x []T, y []T) []T { | ||
result := make([]T, 0) | ||
for _, item := range x { | ||
if !slices.Contains(y, item) { | ||
result = append(result, item) | ||
} | ||
func generateDiskSpec(provisioner string) longhornv1.DiskSpec { | ||
diskType := longhornv1.DiskTypeFilesystem | ||
if provisioner == "longhornv2" { | ||
diskType = longhornv1.DiskTypeBlock | ||
} | ||
spec := longhornv1.DiskSpec{ | ||
Type: diskType, | ||
AllowScheduling: true, | ||
EvictionRequested: false, | ||
StorageReserved: 0, | ||
} | ||
return result | ||
return spec | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package utils | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
@@ -175,3 +176,14 @@ func CallerWithCondLock[T any](cond *sync.Cond, f func() T) T { | |
defer cond.L.Unlock() | ||
return f() | ||
} | ||
|
||
// DoCommand executes a command and returns the stdout, stderr and error | ||
func DoCommand(cmdString string) (string, string, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This function is quite general. Not sure if there is an existing lib able to use or even we can add this to common lib for other repos to reuse later if appropriate. Can extend it to pass io.Writer out and err instead of hard-coded bytes buffer here only. If for testing only, why not just add this to a related test package folder? |
||
var stdout bytes.Buffer | ||
var stderr bytes.Buffer | ||
cmd := exec.Command("bash", "-c", cmdString) | ||
cmd.Stdout = &stdout | ||
cmd.Stderr = &stderr | ||
err := cmd.Run() | ||
return stdout.String(), stderr.String(), err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Do we have a mutator mechanism to add the default value? If yes, we can prevent this sort of non-biz code in controller.