Skip to content

Commit

Permalink
Compare labels and annotations using maps.Equal
Browse files Browse the repository at this point in the history
The maps package was introduced in go 1.21.
  • Loading branch information
avorima committed Mar 13, 2024
1 parent 1382d7d commit f108153
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/predicate/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package predicate

import (
"reflect"
"maps"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -198,7 +198,7 @@ func (AnnotationChangedPredicate) Update(e event.UpdateEvent) bool {
return false
}

return !reflect.DeepEqual(e.ObjectNew.GetAnnotations(), e.ObjectOld.GetAnnotations())
return !maps.Equal(e.ObjectNew.GetAnnotations(), e.ObjectOld.GetAnnotations())
}

// LabelChangedPredicate implements a default update predicate function on label change.
Expand Down Expand Up @@ -229,7 +229,7 @@ func (LabelChangedPredicate) Update(e event.UpdateEvent) bool {
return false
}

return !reflect.DeepEqual(e.ObjectNew.GetLabels(), e.ObjectOld.GetLabels())
return !maps.Equal(e.ObjectNew.GetLabels(), e.ObjectOld.GetLabels())
}

// And returns a composite predicate that implements a logical AND of the predicates passed to it.
Expand Down

0 comments on commit f108153

Please sign in to comment.