Skip to content

Commit

Permalink
volrep: Simplify annotation check
Browse files Browse the repository at this point in the history
The check is trivial, ensuring that both pvc and pv have the expected
annotation value. The code was too complicated, using complex way to
access map value, adding 5 temporary variables, and complex conditions.

Simplify to the simplest possible form that anyone will understand
quickly.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs committed Jan 28, 2025
1 parent 6f53cc3 commit 44801de
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions internal/controller/vrg_volrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,27 +575,18 @@ func (v *VRGInstance) generateArchiveAnnotation(gen int64) string {
}

func (v *VRGInstance) isArchivedAlready(pvc *corev1.PersistentVolumeClaim, log logr.Logger) bool {
pvHasAnnotation := false
pvcHasAnnotation := false

pv, err := v.getPVFromPVC(pvc)
if err != nil {
log.Error(err, "Failed to get PV to check if archived")

return false
}

pvcDesiredValue := v.generateArchiveAnnotation(pvc.Generation)
if v, ok := pvc.ObjectMeta.Annotations[pvcVRAnnotationArchivedKey]; ok && (v == pvcDesiredValue) {
pvcHasAnnotation = true
}

pvDesiredValue := v.generateArchiveAnnotation(pv.Generation)
if v, ok := pv.ObjectMeta.Annotations[pvcVRAnnotationArchivedKey]; ok && (v == pvDesiredValue) {
pvHasAnnotation = true
if pvc.Annotations[pvcVRAnnotationArchivedKey] != v.generateArchiveAnnotation(pvc.Generation) {
return false
}

if !pvHasAnnotation || !pvcHasAnnotation {
if pv.Annotations[pvcVRAnnotationArchivedKey] != v.generateArchiveAnnotation(pv.Generation) {
return false
}

Expand Down

0 comments on commit 44801de

Please sign in to comment.