Skip to content

Commit

Permalink
controller: drop spec.filesystem.provisioned
Browse files Browse the repository at this point in the history
    - Now we only check the `spec.provision`

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
  • Loading branch information
Vicente-Cheng committed Oct 8, 2024
1 parent 230565b commit 78e6c3d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
43 changes: 28 additions & 15 deletions pkg/controller/blockdevice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (c *Controller) OnBlockDeviceChange(_ string, device *diskv1.BlockDevice) (
logrus.Warnf("Failed to generate provisioner for device %s: %v", device.Name, err)
return nil, err
}
if !reflect.DeepEqual(device, deviceCpy) {
logrus.Debugf("Update block device %s for new provisioner state", device.Name)
return c.Blockdevices.Update(deviceCpy)
}
if provisionerInst == nil {
logrus.Infof("Skip device %s as no provisioner found or not configured", device.Name)
return nil, nil
Expand Down Expand Up @@ -207,26 +211,32 @@ func (c *Controller) finalizeBlockDevice(oldBd, newBd *diskv1.BlockDevice, devPa
}

func (c *Controller) generateProvisioner(device *diskv1.BlockDevice) (provisioner.Provisioner, error) {
if device.Spec.Provisioner == nil && !device.Spec.FileSystem.Provisioned && device.Status.ProvisionPhase != diskv1.ProvisionPhaseProvisioned {
// skip the non-provisioned device
if device.Spec.Provisioner == nil && device.Status.ProvisionPhase != diskv1.ProvisionPhaseProvisioned {
return nil, nil
}
// upgrade case, we need to update some fields
if device.Spec.Provisioner == nil && device.Status.ProvisionPhase == diskv1.ProvisionPhaseProvisioned {
device.Spec.Provision = true
device.Spec.FileSystem.Provisioned = false
provisionerLHV1 := &diskv1.LonghornProvisionerInfo{
EngineVersion: provisioner.TypeLonghornV1,
}
device.Spec.Provisioner = &diskv1.ProvisionerInfo{
Longhorn: provisionerLHV1,
}
return nil, nil
}
logrus.Infof("Generate provisioner from device %s, content: %v", device.Name, device.Spec.Provisioner)
// set default
provisionerType := provisioner.TypeLonghornV1
if device.Spec.Provisioner != nil {
// **TODO**: we should use webhook to validate the provisioner type (and number)
numProvisioner := 0
if device.Spec.Provisioner.Longhorn != nil {
numProvisioner++
provisionerType = device.Spec.Provisioner.Longhorn.EngineVersion
}
if device.Spec.Provisioner.LVM != nil {
numProvisioner++
provisionerType = provisioner.TypeLVM
}
if numProvisioner > 1 {
return nil, fmt.Errorf("multiple provisioner types found for block device %s", device.Name)
}
}
switch provisionerType {
case provisioner.TypeLonghornV1:
Expand Down Expand Up @@ -315,7 +325,13 @@ func (c *Controller) updateDeviceStatus(device *diskv1.BlockDevice, devPath stri
if needAutoProvision {
logrus.Infof("Auto provisioning block device %s", device.Name)
device.Spec.FileSystem.ForceFormatted = true
device.Spec.FileSystem.Provisioned = true
device.Spec.Provision = true
device.Spec.Provisioner = &diskv1.ProvisionerInfo{
Longhorn: &diskv1.LonghornProvisionerInfo{
EngineVersion: provisioner.TypeLonghornV1,
},
}

}
return nil
}
Expand Down Expand Up @@ -402,16 +418,13 @@ func canSkipBlockDeviceChange(device *diskv1.BlockDevice, nodeName string) bool
}

func needProvisionerUnprovision(device *diskv1.BlockDevice) bool {
return (!device.Spec.FileSystem.Provisioned && !device.Spec.Provision) &&
device.Status.ProvisionPhase != diskv1.ProvisionPhaseUnprovisioned
return !device.Spec.Provision && device.Status.ProvisionPhase != diskv1.ProvisionPhaseUnprovisioned
}

func needProvisionerUpdate(oldBd, newBd *diskv1.BlockDevice) bool {
return oldBd.Status.ProvisionPhase == diskv1.ProvisionPhaseProvisioned &&
(newBd.Spec.FileSystem.Provisioned || newBd.Spec.Provision)
return oldBd.Status.ProvisionPhase == diskv1.ProvisionPhaseProvisioned && newBd.Spec.Provision
}

func needProvisionerProvision(oldBd, newBd *diskv1.BlockDevice) bool {
return oldBd.Status.ProvisionPhase == diskv1.ProvisionPhaseUnprovisioned &&
(newBd.Spec.FileSystem.Provisioned || newBd.Spec.Provision)
return oldBd.Status.ProvisionPhase == diskv1.ProvisionPhaseUnprovisioned && newBd.Spec.Provision
}
10 changes: 8 additions & 2 deletions pkg/controller/blockdevice/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/harvester/node-disk-manager/pkg/block"
"github.com/harvester/node-disk-manager/pkg/filter"
ctldiskv1 "github.com/harvester/node-disk-manager/pkg/generated/controllers/harvesterhci.io/v1beta1"
"github.com/harvester/node-disk-manager/pkg/provisioner"
)

type Scanner struct {
Expand Down Expand Up @@ -291,7 +292,12 @@ func (s *Scanner) SaveBlockDevice(bd *diskv1.BlockDevice, autoProvisioned bool)
if errors.IsNotFound(err) {
if autoProvisioned {
bd.Spec.FileSystem.ForceFormatted = true
bd.Spec.FileSystem.Provisioned = true
bd.Spec.Provision = true
bd.Spec.Provisioner = &diskv1.ProvisionerInfo{
Longhorn: &diskv1.LonghornProvisionerInfo{
EngineVersion: provisioner.TypeLonghornV1,
},
}
}
logrus.Infof("Add new block device %s with device: %s", bd.Name, bd.Spec.DevPath)
return s.Blockdevices.Create(bd)
Expand All @@ -309,7 +315,7 @@ func (s *Scanner) SaveBlockDevice(bd *diskv1.BlockDevice, autoProvisioned bool)
// - disk hasn't yet been force formatted
// - disk matches auto-provisioned patterns
func (s *Scanner) NeedsAutoProvision(oldBd *diskv1.BlockDevice, autoProvisionPatternMatches bool) bool {
return !oldBd.Spec.FileSystem.Provisioned && !oldBd.Spec.Provision && autoProvisionPatternMatches && oldBd.Status.DeviceStatus.FileSystem.LastFormattedAt == nil
return !oldBd.Spec.Provision && autoProvisionPatternMatches && oldBd.Status.DeviceStatus.FileSystem.LastFormattedAt == nil
}

// isDevPathChanged returns true if the device path has changed.
Expand Down
2 changes: 1 addition & 1 deletion pkg/provisioner/longhornv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func needUpdateMountPoint(bd *diskv1.BlockDevice, filesystem *block.FileSystemIn
return NeedMountUpdateNoOp
}

provisioned := bd.Spec.FileSystem.Provisioned || bd.Spec.Provision
provisioned := bd.Spec.Provision
logrus.Debugf("Checking mount operation with FS.Provisioned %v, FS.Mountpoint %s", provisioned, filesystem.MountPoint)
if provisioned {
if filesystem.MountPoint == "" {
Expand Down

0 comments on commit 78e6c3d

Please sign in to comment.