Skip to content

Commit

Permalink
Merge pull request #250 from nbalacha/filter
Browse files Browse the repository at this point in the history
refactor: move function to different file
  • Loading branch information
openshift-merge-robot authored Sep 1, 2022
2 parents e022411 + 92999ad commit 3c15311
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
39 changes: 0 additions & 39 deletions pkg/vgmanager/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,6 @@ const (
usableDeviceType = "usableDeviceType"
)

// filterAvailableDevices returns:
// validDevices: the list of blockdevices considered available
// delayedDevices: the list of blockdevices considered available, but first observed less than 'minDeviceAge' time ago
// error
func (r *VGReconciler) filterAvailableDevices(blockDevices []internal.BlockDevice) ([]internal.BlockDevice, []internal.BlockDevice, error) {
var availableDevices, delayedDevices []internal.BlockDevice
// using a label so `continue DeviceLoop` can be used to skip devices
DeviceLoop:
for _, blockDevice := range blockDevices {

// store device in deviceAgeMap
r.deviceAgeMap.storeDeviceAge(blockDevice.KName)

devLogger := r.Log.WithValues("Device.Name", blockDevice.Name)
for name, filter := range FilterMap {
var valid bool
var err error
filterLogger := devLogger.WithValues("filter.Name", name)
valid, err = filter(blockDevice, r.executor)
if err != nil {
filterLogger.Error(err, "filter error")
valid = false
continue DeviceLoop
} else if !valid {
filterLogger.Info("does not match filter")
continue DeviceLoop
}
}
// check if the device is older than deviceMinAge
isOldEnough := r.deviceAgeMap.isOlderThan(blockDevice.KName)
if isOldEnough {
availableDevices = append(availableDevices, blockDevice)
} else {
delayedDevices = append(delayedDevices, blockDevice)
}
}
return availableDevices, delayedDevices, nil
}

// maps of function identifier (for logs) to filter function.
// These are passed the localv1alpha1.DeviceInclusionSpec to make testing easier,
// but they aren't expected to use it
Expand Down
39 changes: 39 additions & 0 deletions pkg/vgmanager/vgmanager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,42 @@ func (r *VGReconciler) getAllLvmVolumeGroups(ctx context.Context) (map[string]*l

return lvmVolumeGroupsMap, nil
}

// filterAvailableDevices returns:
// validDevices: the list of blockdevices considered available
// delayedDevices: the list of blockdevices considered available, but first observed less than 'minDeviceAge' time ago
// error
func (r *VGReconciler) filterAvailableDevices(blockDevices []internal.BlockDevice) ([]internal.BlockDevice, []internal.BlockDevice, error) {
var availableDevices, delayedDevices []internal.BlockDevice
// using a label so `continue DeviceLoop` can be used to skip devices
DeviceLoop:
for _, blockDevice := range blockDevices {

// store device in deviceAgeMap
r.deviceAgeMap.storeDeviceAge(blockDevice.KName)

devLogger := r.Log.WithValues("Device.Name", blockDevice.Name)
for name, filter := range FilterMap {
var valid bool
var err error
filterLogger := devLogger.WithValues("filter.Name", name)
valid, err = filter(blockDevice, r.executor)
if err != nil {
filterLogger.Error(err, "filter error")
valid = false
continue DeviceLoop
} else if !valid {
filterLogger.Info("does not match filter")
continue DeviceLoop
}
}
// check if the device is older than deviceMinAge
isOldEnough := r.deviceAgeMap.isOlderThan(blockDevice.KName)
if isOldEnough {
availableDevices = append(availableDevices, blockDevice)
} else {
delayedDevices = append(delayedDevices, blockDevice)
}
}
return availableDevices, delayedDevices, nil
}

0 comments on commit 3c15311

Please sign in to comment.