Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
nirs committed Jan 27, 2025
1 parent 5167584 commit b2a1dbf
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
@@ -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
}

0 comments on commit b2a1dbf

Please sign in to comment.