From bd9ec466a9a113d65b28a5570663e28f8941bcf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20M=C3=B6ller?= Date: Tue, 24 Sep 2024 12:51:02 +0200 Subject: [PATCH] fix: make sure that wipes are recorded by node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakob Möller --- internal/controllers/constants/constants.go | 4 ++-- internal/controllers/vgmanager/wipe_devices.go | 4 ++-- internal/controllers/vgmanager/wipe_devices_test.go | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/controllers/constants/constants.go b/internal/controllers/constants/constants.go index c0d65512a..81ee0aeb8 100644 --- a/internal/controllers/constants/constants.go +++ b/internal/controllers/constants/constants.go @@ -41,8 +41,8 @@ const ( WorkloadPartitioningManagementAnnotation = "target.workload.openshift.io/management" ManagementAnnotationVal = `{"effect": "PreferredDuringScheduling"}` - // DevicesWipedAnnotation is an annotation that marks when a device has been wiped - DevicesWipedAnnotation = "devices.lvms.openshift.io/wiped" + // DevicesWipedAnnotationPrefix is an annotation prefix that marks when a device has been wiped on a certain node + DevicesWipedAnnotationPrefix = "wiped.devices.lvms.openshift.io/" // labels and values diff --git a/internal/controllers/vgmanager/wipe_devices.go b/internal/controllers/vgmanager/wipe_devices.go index 19d0c5387..2d89194e1 100644 --- a/internal/controllers/vgmanager/wipe_devices.go +++ b/internal/controllers/vgmanager/wipe_devices.go @@ -58,7 +58,7 @@ func (r *Reconciler) wipeDevices( if volumeGroup.Annotations == nil { volumeGroup.Annotations = make(map[string]string) } - volumeGroup.Annotations[constants.DevicesWipedAnnotation] = fmt.Sprintf( + volumeGroup.Annotations[constants.DevicesWipedAnnotationPrefix+r.NodeName] = fmt.Sprintf( "the devices of this volume group have been wiped at %s by lvms according to policy. This marker"+ "serves as indicator that the devices have been wiped before and should not be wiped again."+ "removal of this annotation is unsupported and may lead to data loss due to additional wiping.", @@ -92,7 +92,7 @@ func (r *Reconciler) shouldWipeDevicesOnVolumeGroup(vg *lvmv1alpha1.LVMVolumeGro // If the devices have not been wiped before, they should be wiped. var wipedBefore bool if vg.Annotations != nil { - _, wipedBefore = vg.Annotations[constants.DevicesWipedAnnotation] + _, wipedBefore = vg.Annotations[constants.DevicesWipedAnnotationPrefix+r.NodeName] } return !wipedBefore diff --git a/internal/controllers/vgmanager/wipe_devices_test.go b/internal/controllers/vgmanager/wipe_devices_test.go index 904acfa10..6a4b3646b 100644 --- a/internal/controllers/vgmanager/wipe_devices_test.go +++ b/internal/controllers/vgmanager/wipe_devices_test.go @@ -167,6 +167,7 @@ func TestWipeDevices(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ctx := log.IntoContext(context.Background(), testr.New(t)) r := &Reconciler{ + NodeName: "test", Wipefs: mockWipefs, Dmsetup: mockDmsetup, SymlinkResolveFn: func(path string) (string, error) { return path, nil }, @@ -187,7 +188,8 @@ func TestWipeDevices(t *testing.T) { } if tt.wipedBefore { - volumeGroup.Annotations = map[string]string{constants.DevicesWipedAnnotation: time.Now().Format(time.RFC3339)} + volumeGroup.Annotations = map[string]string{ + constants.DevicesWipedAnnotationPrefix + r.NodeName: time.Now().Format(time.RFC3339)} } wiped, err := r.wipeDevices(ctx, volumeGroup, tt.blockDevices, symlinkResolver.NewWithResolver(r.SymlinkResolveFn))