Skip to content

Commit

Permalink
fix(prometheusrule): compare to SLO object (#89)
Browse files Browse the repository at this point in the history
- instead of nil

Signed-off-by: Hy3n4 <[email protected]>
  • Loading branch information
Hy3n4 authored Mar 20, 2024
1 parent cac4705 commit b13e740
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (r *PrometheusRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}

// if not, check if we are supposed to manage it or not
if slo == nil {
if reflect.DeepEqual(slo, &openslov1.SLO{}) {
value, found := prometheusRule.ObjectMeta.Labels["osko.dev/manage"]
if !found || value != "true" {
log.Info("Not managing a PrometheusRule unrelated to osko")
Expand Down Expand Up @@ -105,7 +105,7 @@ func (r *PrometheusRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reque
err = utils.UpdateStatus(ctx, slo, r.Client, "Ready", metav1.ConditionFalse, "SLI Object not found")
if err != nil {
log.Error(err, "Failed to update SLO status")
//r.Recorder.Event(slo, "Error", "SLIObjectNotFound", "SLI Object not found")
r.Recorder.Event(slo, "Warning", "SLIObjectNotFound", "SLI Object not found")
return ctrl.Result{}, nil
}
log.Error(err, "SLO has no SLI reference")
Expand All @@ -116,14 +116,7 @@ func (r *PrometheusRuleReconciler) Reconcile(ctx context.Context, req ctrl.Reque
log.Info("PrometheusRule not found. Let's make one.")
prometheusRule, err = helpers.CreatePrometheusRule(slo, sli)
if err != nil {
err = utils.UpdateStatus(
ctx,
slo,
r.Client,
"Ready",
metav1.ConditionFalse,
"Failed to create Prometheus Rule",
)
err = utils.UpdateStatus(ctx, slo, r.Client, "Ready", metav1.ConditionFalse, "Failed to create Prometheus Rule")
if err != nil {
log.Error(err, "Failed to update SLO status")
return ctrl.Result{}, err
Expand Down
3 changes: 0 additions & 3 deletions internal/helpers/prometheus_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func (mrs *MonitoringRuleSet) createBaseRuleLabels(window string) map[string]str
"slo_name": mrs.Slo.Name,
"window": window,
}

}

func (mrs *MonitoringRuleSet) createUserDefinedRuleLabels() map[string]string {
Expand Down Expand Up @@ -300,8 +299,6 @@ func (mrs *MonitoringRuleSet) SetupRules() ([]monitoringv1.RuleGroup, error) {
}

func CreatePrometheusRule(slo *openslov1.SLO, sli *openslov1.SLI) (*monitoringv1.PrometheusRule, error) {
// log := ctrllog.FromContext(context.Background())

mrs := &MonitoringRuleSet{
Slo: slo,
Sli: sli,
Expand Down

0 comments on commit b13e740

Please sign in to comment.