Skip to content

Commit

Permalink
drop spec.filesystem.provisioned
Browse files Browse the repository at this point in the history
Signed-off-by: Vicente Cheng <[email protected]>
  • Loading branch information
Vicente-Cheng committed Oct 6, 2024
1 parent 901728c commit 6571402
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
35 changes: 21 additions & 14 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 @@ -402,16 +412,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
}
4 changes: 2 additions & 2 deletions pkg/controller/blockdevice/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ 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
}
logrus.Infof("Add new block device %s with device: %s", bd.Name, bd.Spec.DevPath)
return s.Blockdevices.Create(bd)
Expand All @@ -309,7 +309,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 6571402

Please sign in to comment.