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

OCPVE-600: fix: wiping should not error on optional paths #435

Merged
merged 1 commit into from
Oct 3, 2023
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
17 changes: 15 additions & 2 deletions pkg/vgmanager/wipe_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import (
)

func (r *VGReconciler) wipeDevicesIfNecessary(ctx context.Context, volumeGroup *lvmv1alpha1.LVMVolumeGroup, nodeStatus *lvmv1alpha1.LVMVolumeGroupNodeStatus, blockDevices []lsblk.BlockDevice) (bool, error) {
logger := log.FromContext(ctx)

if volumeGroup.Spec.DeviceSelector == nil || volumeGroup.Spec.DeviceSelector.ForceWipeDevicesAndDestroyAllData == nil || !*volumeGroup.Spec.DeviceSelector.ForceWipeDevicesAndDestroyAllData {
return false, nil
}

allPaths := append(volumeGroup.Spec.DeviceSelector.Paths, volumeGroup.Spec.DeviceSelector.OptionalPaths...)
wiped := false
for _, path := range allPaths {
for _, path := range volumeGroup.Spec.DeviceSelector.Paths {
if isDeviceAlreadyPartOfVG(nodeStatus, path, volumeGroup) { // Do not only check the vg devices, but also node status device paths
continue
}
Expand All @@ -30,6 +31,18 @@ func (r *VGReconciler) wipeDevicesIfNecessary(ctx context.Context, volumeGroup *
wiped = true
}
}
for _, path := range volumeGroup.Spec.DeviceSelector.OptionalPaths {
if isDeviceAlreadyPartOfVG(nodeStatus, path, volumeGroup) {
continue
}
deviceWiped, err := r.wipeDevice(ctx, path, blockDevices)
if err != nil {
logger.Info(fmt.Sprintf("skipping wiping optional device %s: %v", path, err))
}
if deviceWiped {
wiped = true
}
}

return wiped, nil
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/vgmanager/wipe_devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestWipeDevices(t *testing.T) {
name string
forceWipeNotEnabled bool
devicePaths []string
optionalDevicePaths []string
blockDevices []lsblk.BlockDevice
nodeStatus v1alpha1.LVMVolumeGroupNodeStatus
wipeCount int
Expand Down Expand Up @@ -111,6 +112,30 @@ func TestWipeDevices(t *testing.T) {
wipeCount: 2,
removeReferenceCount: 1,
},
{
name: "One required and one optional device exist in the device list",
devicePaths: []string{"/dev/loop1"},
optionalDevicePaths: []string{"/dev/loop2"},
blockDevices: []lsblk.BlockDevice{{KName: "/dev/sda"}, {KName: "/dev/loop1"}, {KName: "/dev/loop2", Children: []lsblk.BlockDevice{{KName: "/dev/loop2p1"}}}},
nodeStatus: v1alpha1.LVMVolumeGroupNodeStatus{Spec: v1alpha1.LVMVolumeGroupNodeStatusSpec{
LVMVGStatus: []v1alpha1.VGStatus{
{Name: "vg1", Devices: []string{"/dev/sda"}}},
}},
wipeCount: 2,
removeReferenceCount: 1,
},
{
name: "Optional device does not exist in the device list",
devicePaths: []string{"/dev/loop1"},
optionalDevicePaths: []string{"/dev/loop2"},
blockDevices: []lsblk.BlockDevice{{KName: "/dev/sda"}, {KName: "/dev/loop1"}},
nodeStatus: v1alpha1.LVMVolumeGroupNodeStatus{Spec: v1alpha1.LVMVolumeGroupNodeStatusSpec{
LVMVGStatus: []v1alpha1.VGStatus{
{Name: "vg1", Devices: []string{"/dev/sda"}}},
}},
wipeCount: 1,
removeReferenceCount: 0,
},
{
name: "Both devices, one of them is a child, exist in the device list",
devicePaths: []string{"/dev/loop1", "/dev/loop2p1"},
Expand Down Expand Up @@ -160,6 +185,7 @@ func TestWipeDevices(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{Name: "vg1"},
Spec: v1alpha1.LVMVolumeGroupSpec{DeviceSelector: &v1alpha1.DeviceSelector{
Paths: tt.devicePaths,
OptionalPaths: tt.optionalDevicePaths,
ForceWipeDevicesAndDestroyAllData: ptr.To[bool](!tt.forceWipeNotEnabled),
}},
}
Expand Down