Skip to content

Commit 172fdfe

Browse files
Merge pull request #380 from jakobmoellerdev/OCPVE-622-deviceMinAge
OCPVE-622: chore: remove deviceMinAge due to imperfect validation
2 parents fc2a919 + e180edf commit 172fdfe

File tree

5 files changed

+20
-198
lines changed

5 files changed

+20
-198
lines changed

pkg/vgmanager/device_age.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

pkg/vgmanager/device_age_test.go

Lines changed: 0 additions & 60 deletions
This file was deleted.

pkg/vgmanager/devices.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,37 +68,28 @@ func (r *VGReconciler) addDevicesToVG(vgs []VolumeGroup, vgName string, devices
6868
}
6969

7070
// getAvailableDevicesForVG determines the available devices that can be used to create a volume group.
71-
func (r *VGReconciler) getAvailableDevicesForVG(blockDevices []internal.BlockDevice, vgs []VolumeGroup, volumeGroup *lvmv1alpha1.LVMVolumeGroup) ([]internal.BlockDevice, []internal.BlockDevice, error) {
71+
func (r *VGReconciler) getAvailableDevicesForVG(blockDevices []internal.BlockDevice, vgs []VolumeGroup, volumeGroup *lvmv1alpha1.LVMVolumeGroup) ([]internal.BlockDevice, error) {
7272
// filter devices based on DeviceSelector.Paths if specified
7373
availableDevices, err := r.filterMatchingDevices(blockDevices, vgs, volumeGroup)
7474
if err != nil {
7575
r.Log.Error(err, "failed to filter matching devices", "VGName", volumeGroup.Name)
76-
return nil, nil, err
76+
return nil, err
7777
}
7878

79-
// determine only available devices based on device age and filters in FilterMap
80-
availableDevices, delayedDevices := r.filterAvailableDevices(availableDevices)
81-
82-
return availableDevices, delayedDevices, nil
79+
return r.filterAvailableDevices(availableDevices), nil
8380
}
8481

8582
// filterAvailableDevices returns:
8683
// availableDevices: the list of blockdevices considered available
87-
// delayedDevices: the list of blockdevices considered available, but first observed less than 'minDeviceAge' time ago
88-
func (r *VGReconciler) filterAvailableDevices(blockDevices []internal.BlockDevice) ([]internal.BlockDevice, []internal.BlockDevice) {
89-
var availableDevices, delayedDevices []internal.BlockDevice
84+
func (r *VGReconciler) filterAvailableDevices(blockDevices []internal.BlockDevice) []internal.BlockDevice {
85+
var availableDevices []internal.BlockDevice
9086
// using a label so `continue DeviceLoop` can be used to skip devices
9187
DeviceLoop:
9288
for _, blockDevice := range blockDevices {
93-
94-
// store device in deviceAgeMap
95-
r.deviceAgeMap.storeDeviceAge(blockDevice.KName)
96-
9789
// check for partitions recursively
9890
if blockDevice.HasChildren() {
99-
childAvailableDevices, childDelayedDevices := r.filterAvailableDevices(blockDevice.Children)
91+
childAvailableDevices := r.filterAvailableDevices(blockDevice.Children)
10092
availableDevices = append(availableDevices, childAvailableDevices...)
101-
delayedDevices = append(delayedDevices, childDelayedDevices...)
10293
}
10394

10495
devLogger := r.Log.WithValues("Device.Name", blockDevice.Name)
@@ -113,15 +104,9 @@ DeviceLoop:
113104
continue DeviceLoop
114105
}
115106
}
116-
// check if the device is older than deviceMinAge
117-
isOldEnough := r.deviceAgeMap.isOlderThan(blockDevice.KName)
118-
if isOldEnough {
119-
availableDevices = append(availableDevices, blockDevice)
120-
} else {
121-
delayedDevices = append(delayedDevices, blockDevice)
122-
}
107+
availableDevices = append(availableDevices, blockDevice)
123108
}
124-
return availableDevices, delayedDevices
109+
return availableDevices
125110
}
126111

127112
// filterMatchingDevices filters devices based on DeviceSelector.Paths if specified.

pkg/vgmanager/devices_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ func TestAvailableDevicesForVG(t *testing.T) {
2828
}
2929
}
3030

31-
r := &VGReconciler{
32-
deviceAgeMap: newAgeMap(&wallTime{}),
33-
}
31+
r := &VGReconciler{}
3432

3533
// remove noBindMounts filter as it reads `proc/1/mountinfo` file.
3634
delete(FilterMap, "noBindMounts")
@@ -554,14 +552,13 @@ func TestAvailableDevicesForVG(t *testing.T) {
554552

555553
for _, tc := range testCases {
556554
t.Run(tc.description, func(t *testing.T) {
557-
//use delayed devices as available devices in the test, as they are matching all the conditions but device age logic only considers them 30 seconds later
558-
_, delayedDevices, err := r.getAvailableDevicesForVG(tc.existingBlockDevices, tc.existingVGs, &tc.volumeGroup)
555+
availableDevices, err := r.getAvailableDevicesForVG(tc.existingBlockDevices, tc.existingVGs, &tc.volumeGroup)
559556
if !tc.expectError {
560557
assert.NoError(t, err)
561558
} else {
562559
assert.Error(t, err)
563560
}
564-
assert.Equal(t, tc.numOfAvailableDevices, len(delayedDevices), "expected numOfAvailableDevices is not equal to actual number")
561+
assert.Equal(t, tc.numOfAvailableDevices, len(availableDevices), "expected numOfAvailableDevices is not equal to actual number")
565562
})
566563
}
567564
}

pkg/vgmanager/vgmanager_controller.go

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646
const (
4747
ControllerName = "vg-manager"
4848
DefaultChunkSize = "128"
49-
reconcileInterval = 1 * time.Minute
49+
reconcileInterval = 15 * time.Second
5050
)
5151

5252
var (
@@ -55,21 +55,18 @@ var (
5555

5656
// SetupWithManager sets up the controller with the Manager.
5757
func (r *VGReconciler) SetupWithManager(mgr ctrl.Manager) error {
58-
r.deviceAgeMap = newAgeMap(&wallTime{})
5958
return ctrl.NewControllerManagedBy(mgr).
6059
For(&lvmv1alpha1.LVMVolumeGroup{}).
6160
Complete(r)
6261
}
6362

6463
type VGReconciler struct {
6564
client.Client
66-
Scheme *runtime.Scheme
67-
Log logr.Logger
68-
// map from KNAME of device to time when the device was first observed since the process started
69-
deviceAgeMap *ageMap
70-
executor internal.Executor
71-
NodeName string
72-
Namespace string
65+
Scheme *runtime.Scheme
66+
Log logr.Logger
67+
executor internal.Executor
68+
NodeName string
69+
Namespace string
7370
}
7471

7572
func (r *VGReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
@@ -143,35 +140,19 @@ func (r *VGReconciler) reconcile(ctx context.Context, volumeGroup *lvmv1alpha1.L
143140
}
144141

145142
//Get the available block devices that can be used for this volume group
146-
availableDevices, delayedDevices, err := r.getAvailableDevicesForVG(blockDevices, vgs, volumeGroup)
143+
availableDevices, err := r.getAvailableDevicesForVG(blockDevices, vgs, volumeGroup)
147144
if err != nil {
148145
r.Log.Error(err, "failed to get block devices for volumegroup, will retry", "name", volumeGroup.Name)
149-
// Set a failure status only if there is an error and there is no delayed devices. If there are delayed devices, there is a chance that this will pass in the next reconciliation.
150-
if len(delayedDevices) == 0 {
151-
if statuserr := r.setVolumeGroupFailedStatus(ctx, volumeGroup.Name, fmt.Sprintf("failed to get block devices for volumegroup %s: %v", volumeGroup.Name, err.Error())); statuserr != nil {
152-
r.Log.Error(statuserr, "failed to update status", "name", volumeGroup.Name)
153-
}
154-
}
155-
156146
// Failed to get devices for this volume group. Reconcile again.
157147
return reconcileAgain, err
158148
}
159149

160-
r.Log.Info("listing available and delayed devices", "availableDevices", availableDevices, "delayedDevices", delayedDevices)
150+
r.Log.Info("listing available and delayed devices", "availableDevices", availableDevices)
161151

162152
// If there are no available devices, that could mean either
163153
// - There is no available devices to attach to the volume group
164154
// - All the available devices are already attached
165155
if len(availableDevices) == 0 {
166-
if len(delayedDevices) > 0 {
167-
r.Log.Info("there are delayed devices, will retry them in the next reconciliation", "VGName", volumeGroup.Name, "delayedDevices", delayedDevices)
168-
if statuserr := r.setVolumeGroupProgressingStatus(ctx, volumeGroup.Name); statuserr != nil {
169-
r.Log.Error(statuserr, "failed to update status", "VGName", volumeGroup.Name)
170-
return reconcileAgain, statuserr
171-
}
172-
return ctrl.Result{Requeue: true, RequeueAfter: 30 * time.Second}, nil //30 seconds to make sure delayed devices become available
173-
}
174-
175156
devicesExist := false
176157
for _, vg := range vgs {
177158
if volumeGroup.Name == vg.Name {
@@ -262,12 +243,7 @@ func (r *VGReconciler) reconcile(ctx context.Context, volumeGroup *lvmv1alpha1.L
262243
return reconcileAgain, nil
263244
}
264245

265-
// requeue faster if some devices are too recently observed to consume
266-
requeueAfter := time.Minute * 1
267-
if len(delayedDevices) > 0 {
268-
requeueAfter = time.Second * 30
269-
}
270-
return ctrl.Result{RequeueAfter: requeueAfter}, nil
246+
return reconcileAgain, nil
271247
}
272248

273249
func (r *VGReconciler) processDelete(ctx context.Context, volumeGroup *lvmv1alpha1.LVMVolumeGroup) error {

0 commit comments

Comments
 (0)