diff --git a/pkg/vgmanager/filter.go b/pkg/vgmanager/filter.go index be2824041..a8d83412e 100644 --- a/pkg/vgmanager/filter.go +++ b/pkg/vgmanager/filter.go @@ -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 diff --git a/pkg/vgmanager/vgmanager_controller.go b/pkg/vgmanager/vgmanager_controller.go index 3c70930a5..d0c347b92 100644 --- a/pkg/vgmanager/vgmanager_controller.go +++ b/pkg/vgmanager/vgmanager_controller.go @@ -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 +}