From bf3b3ba5902c382fd7ea757d4512bb282a2d8fc7 Mon Sep 17 00:00:00 2001 From: Bartosz Majsak Date: Tue, 12 Dec 2023 22:14:56 +0100 Subject: [PATCH] fix: improves removed annotation predicate (#92) 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.... --- controllers/predicates.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/controllers/predicates.go b/controllers/predicates.go index fa74138..4577d3c 100644 --- a/controllers/predicates.go +++ b/controllers/predicates.go @@ -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)-.*$`)