From 10c949b1f5c6045d52b0ba2be15a38e69e4f24bd Mon Sep 17 00:00:00 2001 From: Mathieu Cesbron Date: Mon, 19 Feb 2024 17:26:25 +0100 Subject: [PATCH] Add rbac for smon and ing --- charts/operator/Chart.yaml | 4 ++-- charts/operator/templates/cluster-role.yaml | 6 ++++++ internal/controller/controller.go | 2 ++ internal/controller/service_monitor.go | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/charts/operator/Chart.yaml b/charts/operator/Chart.yaml index aa0f812..ae70ac5 100644 --- a/charts/operator/Chart.yaml +++ b/charts/operator/Chart.yaml @@ -2,6 +2,6 @@ apiVersion: v2 name: immudb-operator description: Helm chart to deploy [unagex-immudb-operator](https://github.com/unagex/immudb-operator) type: application -version: 0.0.7 -appVersion: 0.0.7 +version: 0.0.8 +appVersion: 0.0.8 home: https://github.com/unagex/immudb-operator diff --git a/charts/operator/templates/cluster-role.yaml b/charts/operator/templates/cluster-role.yaml index 94bec95..d783c0b 100644 --- a/charts/operator/templates/cluster-role.yaml +++ b/charts/operator/templates/cluster-role.yaml @@ -15,3 +15,9 @@ rules: - apiGroups: [""] resources: ["services"] verbs: ["get", "list", "watch", "create", "update"] + - apiGroups: ["networking.k8s.io"] + resources: ["ingresses"] + verbs: ["get", "list", "watch", "create", "update"] + - apiGroups: ["monitoring.coreos.com"] + resources: ["servicemonitors"] + verbs: ["get", "list", "watch", "create", "update"] diff --git a/internal/controller/controller.go b/internal/controller/controller.go index d3bcb13..0970998 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -32,6 +32,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" + promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" unagexcomv1 "github.com/unagex/immudb-operator/api/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -104,5 +105,6 @@ func (r *ImmudbReconciler) SetupWithManager(mgr ctrl.Manager) error { Watches(&appsv1.StatefulSet{}, filter). Watches(&corev1.Service{}, filter). Watches(&knetworkingv1.Ingress{}, filter). + Watches(&promv1.ServiceMonitor{}, filter). Complete(r) } diff --git a/internal/controller/service_monitor.go b/internal/controller/service_monitor.go index c4c4ecd..19fe977 100644 --- a/internal/controller/service_monitor.go +++ b/internal/controller/service_monitor.go @@ -8,6 +8,7 @@ import ( "github.com/unagex/immudb-operator/internal/controller/common" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" promv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" @@ -51,7 +52,7 @@ func (r *ImmudbReconciler) GetServiceMonitor(immudb *unagexcomv1.Immudb) *promv1 Name: immudb.Name, Namespace: immudb.Namespace, OwnerReferences: common.GetOwnerReferences(immudb), - Labels: immudb.Spec.ServiceMonitor.Labels, + Labels: labels.Merge(ls, immudb.Spec.ServiceMonitor.Labels), }, Spec: promv1.ServiceMonitorSpec{ Selector: metav1.LabelSelector{