Skip to content

Commit

Permalink
reflect.DeepEqual added
Browse files Browse the repository at this point in the history
  • Loading branch information
gizas committed Jan 9, 2024
1 parent 8629378 commit 05ed573
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions kubernetes/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func (n *namespacePodUpdater) OnUpdate(obj interface{}) {
cachedNamespace, ok := cachedObject.(*Namespace)

if ok && ns.Name == cachedNamespace.Name {
labelscheck := isEqualMetadata(ns.ObjectMeta.Labels, cachedNamespace.ObjectMeta.Labels)
annotationscheck := isEqualMetadata(ns.ObjectMeta.Annotations, cachedNamespace.ObjectMeta.Annotations)
labelscheck := reflect.DeepEqual(ns.ObjectMeta.Labels, cachedNamespace.ObjectMeta.Labels)
annotationscheck := reflect.DeepEqual(ns.ObjectMeta.Annotations, cachedNamespace.ObjectMeta.Annotations)
// Only if there is a difference in Metadata labels or annotations proceed to Pod update
if !labelscheck || !annotationscheck {
for _, pod := range n.store.List() {
Expand Down Expand Up @@ -244,8 +244,8 @@ func (n *nodePodUpdater) OnUpdate(obj interface{}) {
cachedNode, ok := cachedObject.(*Node)

if ok && node.Name == cachedNode.Name {
labelscheck := isEqualMetadata(node.ObjectMeta.Labels, cachedNode.ObjectMeta.Labels)
annotationscheck := isEqualMetadata(node.ObjectMeta.Annotations, cachedNode.ObjectMeta.Annotations)
labelscheck := reflect.DeepEqual(node.ObjectMeta.Labels, cachedNode.ObjectMeta.Labels)
annotationscheck := reflect.DeepEqual(node.ObjectMeta.Annotations, cachedNode.ObjectMeta.Annotations)
// Only if there is a difference in Metadata labels or annotations proceed to Pod update
if !labelscheck || !annotationscheck {
for _, pod := range n.store.List() {
Expand All @@ -265,9 +265,3 @@ func (*nodePodUpdater) OnAdd(interface{}) {}
// OnDelete handles delete events on namespaces. Nothing to do, if pods are deleted from this
// namespace they will generate their own delete events.
func (*nodePodUpdater) OnDelete(interface{}) {}

// isEqualMetadata receives labels or annotations maps and checks their equality. Returns True if equal, False if there is a difference
func isEqualMetadata(newmetadata, oldmetadata map[string]string) bool {
check := reflect.DeepEqual(newmetadata, oldmetadata)
return check
}

0 comments on commit 05ed573

Please sign in to comment.