Skip to content

Commit

Permalink
monitoring: update label on prometheus resources
Browse files Browse the repository at this point in the history
Updating the promethes reources (PrometheusRule and ServiceMonitor) is
done by fetching the current resource from the server and updating the
spec on it. This commit makes it also apply the labels, so users can
update them via rook CRDs.

Closes: #9241
Signed-off-by: Mara Sophie Grosch <littlefox@lf-net.org>
  • Loading branch information
LittleFox94 committed Nov 24, 2021
1 parent e008464 commit 733878b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/operator/k8sutil/prometheus.go
Expand Up @@ -80,6 +80,7 @@ func CreateOrUpdateServiceMonitor(serviceMonitorDefinition *monitoringv1.Service
return nil, fmt.Errorf("failed to retrieve servicemonitor. %v", err)
}
oldSm.Spec = serviceMonitorDefinition.Spec
oldSm.ObjectMeta.Labels = serviceMonitorDefinition.ObjectMeta.Labels
sm, err := client.MonitoringV1().ServiceMonitors(namespace).Update(ctx, oldSm, metav1.UpdateOptions{})
if err != nil {
return nil, fmt.Errorf("failed to update servicemonitor. %v", err)
Expand Down Expand Up @@ -123,6 +124,7 @@ func CreateOrUpdatePrometheusRule(prometheusRule *monitoringv1.PrometheusRule) (
return nil, fmt.Errorf("failed to get prometheusRule object. %v", err)
}
promRule.Spec = prometheusRule.Spec
promRule.ObjectMeta.Labels = prometheusRule.ObjectMeta.Labels
_, err = client.MonitoringV1().PrometheusRules(namespace).Update(ctx, promRule, metav1.UpdateOptions{})
if err != nil {
return nil, fmt.Errorf("failed to update prometheusRule. %v", err)
Expand Down

0 comments on commit 733878b

Please sign in to comment.