fix rule status set (#5219)
Signed-off-by: junot <junotxiang@kubesphere.io> Signed-off-by: junot <junotxiang@kubesphere.io>
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller"
|
||||
@@ -60,6 +61,28 @@ func (r *ClusterRuleGroupReconciler) Reconcile(ctx context.Context, req reconcil
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
|
||||
// add rule_id label that may have been missed
|
||||
var updated bool
|
||||
for i := range clusterrulegroupList.Items {
|
||||
g := clusterrulegroupList.Items[i]
|
||||
for j := range g.Spec.Rules {
|
||||
if g.Spec.Rules[j].Labels == nil {
|
||||
g.Spec.Rules[j].Labels = make(map[string]string)
|
||||
}
|
||||
if _, ok := g.Spec.Rules[j].Labels[alertingv2beta1.RuleLabelKeyRuleId]; !ok {
|
||||
g.Spec.Rules[j].Labels[alertingv2beta1.RuleLabelKeyRuleId] = string(uuid.NewUUID())
|
||||
err = r.Client.Update(ctx, &g)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if updated {
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
// labels added to rule.labels
|
||||
enforceRuleLabels := map[string]string{
|
||||
RuleLabelKeyRuleLevel: string(ruleLevel),
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller"
|
||||
@@ -59,6 +60,28 @@ func (r *GlobalRuleGroupReconciler) Reconcile(ctx context.Context, req reconcile
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
|
||||
// add rule_id label that may have been missed
|
||||
var updated bool
|
||||
for i := range globalrulegroupList.Items {
|
||||
g := globalrulegroupList.Items[i]
|
||||
for j := range g.Spec.Rules {
|
||||
if g.Spec.Rules[j].Labels == nil {
|
||||
g.Spec.Rules[j].Labels = make(map[string]string)
|
||||
}
|
||||
if _, ok := g.Spec.Rules[j].Labels[alertingv2beta1.RuleLabelKeyRuleId]; !ok {
|
||||
g.Spec.Rules[j].Labels[alertingv2beta1.RuleLabelKeyRuleId] = string(uuid.NewUUID())
|
||||
err = r.Client.Update(ctx, &g)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if updated {
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
// labels added to rule.labels
|
||||
enforceRuleLabels := map[string]string{
|
||||
RuleLabelKeyRuleLevel: string(ruleLevel),
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/controller"
|
||||
@@ -65,6 +66,28 @@ func (r *RuleGroupReconciler) Reconcile(ctx context.Context, req reconcile.Reque
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
|
||||
// add rule_id label that may have been missed
|
||||
var updated bool
|
||||
for i := range rulegroupList.Items {
|
||||
g := rulegroupList.Items[i]
|
||||
for j := range g.Spec.Rules {
|
||||
if g.Spec.Rules[j].Labels == nil {
|
||||
g.Spec.Rules[j].Labels = make(map[string]string)
|
||||
}
|
||||
if _, ok := g.Spec.Rules[j].Labels[alertingv2beta1.RuleLabelKeyRuleId]; !ok {
|
||||
g.Spec.Rules[j].Labels[alertingv2beta1.RuleLabelKeyRuleId] = string(uuid.NewUUID())
|
||||
err = r.Client.Update(ctx, &g)
|
||||
if err != nil {
|
||||
return reconcile.Result{}, err
|
||||
}
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if updated {
|
||||
return reconcile.Result{}, nil
|
||||
}
|
||||
|
||||
// labels added to rule.labels
|
||||
enforceRuleLabels := map[string]string{
|
||||
RuleLabelKeyRuleLevel: string(ruleLevel),
|
||||
|
||||
Reference in New Issue
Block a user