From 996c4cdb3349ed21ece834ca4b71f67e7fd9b925 Mon Sep 17 00:00:00 2001
From: Brad Soper <brad.soper@gmail.com>
Date: Tue, 7 Mar 2023 15:09:19 -0800
Subject: [PATCH] updated the cr template to provide correct permissions,
 updated the image to the latest for kube state metrics 2.8.1

---
 api/v1/monitoring.go                                      | 2 +-
 pkg/monitoring/tmpl/kube-state-metrics/clusterrole.tpl    | 8 ++++++++
 pkg/monitoring/tmpl/kube-state-metrics/dep.tpl            | 4 ++--
 pkg/monitoring/tmpl/kube-state-metrics/servicemonitor.tpl | 2 +-
 4 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/api/v1/monitoring.go b/api/v1/monitoring.go
index a65301f7..167878be 100644
--- a/api/v1/monitoring.go
+++ b/api/v1/monitoring.go
@@ -179,7 +179,7 @@ var infraMonitoringDefault = CnvrgInfraMonitoring{
 	},
 	KubeStateMetrics: KubeStateMetrics{
 		Enabled: false,
-		Image:   "kube-state-metrics:v1.9.7",
+		Image:   "kube-state-metrics:v2.8.1",
 	},
 	NodeExporter: NodeExporter{
 		Enabled: false,
diff --git a/pkg/monitoring/tmpl/kube-state-metrics/clusterrole.tpl b/pkg/monitoring/tmpl/kube-state-metrics/clusterrole.tpl
index eb4d5932..1071f747 100644
--- a/pkg/monitoring/tmpl/kube-state-metrics/clusterrole.tpl
+++ b/pkg/monitoring/tmpl/kube-state-metrics/clusterrole.tpl
@@ -112,6 +112,14 @@ rules:
   - networking.k8s.io
   resources:
   - networkpolicies
+  - ingresses
+  verbs:
+  - list
+  - watch
+- apiGroups:
+  - coordination.k8s.io
+  resources:
+  - leases
   verbs:
   - list
   - watch
diff --git a/pkg/monitoring/tmpl/kube-state-metrics/dep.tpl b/pkg/monitoring/tmpl/kube-state-metrics/dep.tpl
index b127af5b..ff61d6d0 100644
--- a/pkg/monitoring/tmpl/kube-state-metrics/dep.tpl
+++ b/pkg/monitoring/tmpl/kube-state-metrics/dep.tpl
@@ -7,7 +7,7 @@ metadata:
     {{- end }}
   labels:
     app.kubernetes.io/name: kube-state-metrics
-    app.kubernetes.io/version: v1.9.7
+    app.kubernetes.io/version: v2.8.1
     {{- range $k, $v := .Spec.Labels }}
     {{$k}}: "{{$v}}"
     {{- end }}
@@ -26,7 +26,7 @@ spec:
         {{- end }}
       labels:
         app.kubernetes.io/name: kube-state-metrics
-        app.kubernetes.io/version: v1.9.7
+        app.kubernetes.io/version: v2.8.1
         {{- range $k, $v := .Spec.Labels }}
         {{$k}}: "{{$v}}"
         {{- end }}
diff --git a/pkg/monitoring/tmpl/kube-state-metrics/servicemonitor.tpl b/pkg/monitoring/tmpl/kube-state-metrics/servicemonitor.tpl
index e995faa4..1d47448b 100644
--- a/pkg/monitoring/tmpl/kube-state-metrics/servicemonitor.tpl
+++ b/pkg/monitoring/tmpl/kube-state-metrics/servicemonitor.tpl
@@ -7,7 +7,7 @@ metadata:
     {{- end }}
   labels:
     app.kubernetes.io/name: kube-state-metrics
-    app.kubernetes.io/version: 1.9.7
+    app.kubernetes.io/version: 2.8.1
     cnvrg-infra-prometheus: {{ .Name }}-{{ ns .}}
     {{- range $k, $v := .Spec.Labels }}
     {{$k}}: "{{$v}}"