Skip to content

Commit

Permalink
fix: improves removed annotation predicate (#92)
Browse files Browse the repository at this point in the history
checks if value was set to anything previously and if it is removed now by using second return value (typically called ok or found) of getting value for a given key in the map.

Do not ask me why I wrote it differently in the first attempt....
  • Loading branch information
bartoszmajsak authored Dec 12, 2023
1 parent 323abfd commit bf3b3ba
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion controllers/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func MeshAwareNamespaces() predicate.Funcs {
}

func annotationRemoved(e event.UpdateEvent, annotation string) bool {
return e.ObjectOld.GetAnnotations()[annotation] != "" && e.ObjectNew.GetAnnotations()[annotation] == ""
_, existsInOld := e.ObjectOld.GetAnnotations()[annotation]
_, existsInNew := e.ObjectNew.GetAnnotations()[annotation]

return existsInOld && !existsInNew
}

var reservedNamespaceRegex = regexp.MustCompile(`^(openshift|istio-system)$|^(kube|openshift)-.*$`)
Expand Down

0 comments on commit bf3b3ba

Please sign in to comment.