diff --git a/controllers/libs/monitoring/monitoring.go b/controllers/libs/monitoring/monitoring.go index 515318f4..47f054eb 100644 --- a/controllers/libs/monitoring/monitoring.go +++ b/controllers/libs/monitoring/monitoring.go @@ -12,6 +12,7 @@ package monitoring import ( "math" + "sort" "strconv" "strings" @@ -178,11 +179,23 @@ func MkAlertRuleChecksumString(alertRule monitoringv1.Rule) string { _for := *alertRule.For checksumable += string(_for) } - for k, v := range alertRule.Labels { - checksumable += k + "." + v + + var labels []string + for label := range alertRule.Labels { + labels = append(labels, label) + } + sort.Strings(labels) + for _, label := range labels { + checksumable += label + "." + alertRule.Labels[label] + } + + var annotations []string + for annotation := range alertRule.Annotations { + annotations = append(annotations, annotation) } - for k, v := range alertRule.Annotations { - checksumable += k + ":" + v + sort.Strings(annotations) + for _, annotation := range annotations { + checksumable += annotation + ":" + alertRule.Annotations[annotation] } return checksumable }