Skip to content

Commit

Permalink
Merge pull request #731 from openshift-cherrypick-robot/cherry-pick-7…
Browse files Browse the repository at this point in the history
…30-to-release-4.17

[release-4.17] OCPBUGS-42426: fix: make sure that wipes are recorded by node
  • Loading branch information
suleymanakbas91 authored Sep 25, 2024
2 parents acd82df + bd9ec46 commit bc5e556
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions internal/controllers/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/vgmanager/wipe_devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion internal/controllers/vgmanager/wipe_devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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))
Expand Down

0 comments on commit bc5e556

Please sign in to comment.