From a765914158c224323c9a3e043e89140befb33425 Mon Sep 17 00:00:00 2001 From: junot <49136171+junotx@users.noreply.github.com> Date: Tue, 18 Oct 2022 18:02:38 +0800 Subject: [PATCH] fix empty rules in rulegroup of prometheusrules (#5298) Signed-off-by: junot Signed-off-by: junot --- pkg/controller/alerting/util.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/controller/alerting/util.go b/pkg/controller/alerting/util.go index 55fb6c686..99f94de0e 100644 --- a/pkg/controller/alerting/util.go +++ b/pkg/controller/alerting/util.go @@ -196,6 +196,9 @@ func makePrometheusRuleGroups(log logr.Logger, groupList client.ObjectList, prules = append(prules, *prule) } } + if len(prules) == 0 { + continue + } rulegroups = append(rulegroups, &promresourcesv1.RuleGroup{ Name: group.Name, Interval: group.Spec.Interval, @@ -216,6 +219,9 @@ func makePrometheusRuleGroups(log logr.Logger, groupList client.ObjectList, prules = append(prules, *prule) } } + if len(prules) == 0 { + continue + } rulegroups = append(rulegroups, &promresourcesv1.RuleGroup{ Name: group.Name, Interval: group.Spec.Interval, @@ -238,6 +244,9 @@ func makePrometheusRuleGroups(log logr.Logger, groupList client.ObjectList, prules = append(prules, *prule) } } + if len(prules) == 0 { + continue + } rulegroups = append(rulegroups, &promresourcesv1.RuleGroup{ Name: group.Name, Interval: group.Spec.Interval,