Skip to content
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

refactor: move function to different file #250

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}