From 76328d615f803b5a1e8b8b93b05f2fe78bfe8e2c Mon Sep 17 00:00:00 2001 From: Nacho Barrientos <nacho.barrientos@cern.ch> Date: Wed, 19 Mar 2025 11:06:57 +0100 Subject: [PATCH 1/3] Add standard Helm labels --- templates/_helpers.tpl | 51 +++++++++++++++++++ templates/alertmanager/alertmanager.yaml | 2 + templates/alertmanager/ingress.yaml | 2 + templates/alertmanager/service.yaml | 4 +- templates/api_server/servicemonitor.yaml | 4 +- templates/coredns/servicemonitor.yaml | 4 +- templates/ectd/servicemonitor.yaml | 4 +- templates/fluentbit-logs/clusterrole.yaml | 2 + .../fluentbit-logs/clusterrolebinding.yaml | 2 + .../fluentbit-logs/configmap-luascripts.yaml | 4 +- templates/fluentbit-logs/configmap.yaml | 2 + templates/fluentbit-logs/daemonset.yaml | 2 + templates/fluentbit-logs/serviceaccount.yaml | 2 + .../configmap-luascripts.yaml | 4 +- templates/fluentbit-metrics/configmap.yaml | 2 + templates/fluentbit-metrics/service.yaml | 2 +- templates/fluentbit-metrics/statefulset.yaml | 2 + templates/ingress_nginx/servicemonitor.yaml | 2 + templates/kube_state/clusterrole.yaml | 2 +- templates/kube_state/clusterrolebinding.yaml | 2 +- templates/kube_state/deployment.yaml | 2 +- templates/kube_state/service.yaml | 2 +- templates/kube_state/serviceaccount.yaml | 2 +- templates/kube_state/servicemonitor.yaml | 3 +- templates/kubecontroller/servicemonitor.yaml | 2 + templates/kubelet/servicemonitor.yaml | 2 + templates/kubeproxy/servicemonitor.yaml | 2 + templates/node_exporter/daemonset.yaml | 2 + templates/node_exporter/podmonitor.yaml | 2 + templates/prometheus/clusterrole.yaml | 2 + templates/prometheus/clusterrolebinding.yaml | 2 + .../prometheus/genericservicemonitor.yaml | 4 +- templates/prometheus/prometheus.yaml | 2 + templates/prometheus/remotewritesecret.yaml | 3 +- templates/prometheus/serviceaccount.yaml | 2 + .../prometheus_operator/clusterrole.yaml | 2 + .../clusterrolebinding.yaml | 2 + templates/prometheus_operator/deployment.yaml | 2 + templates/prometheus_operator/service.yaml | 2 + .../prometheus_operator/serviceaccount.yaml | 2 + templates/pushgateway/deployment.yaml | 2 +- templates/pushgateway/ingress.yaml | 2 + templates/pushgateway/service.yaml | 2 +- templates/pushgateway/servicemonitor.yaml | 4 +- templates/scheduler/servicemonitor.yaml | 2 + 45 files changed, 139 insertions(+), 18 deletions(-) create mode 100644 templates/_helpers.tpl diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000..d69a68c --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "cern-it-monitoring-kubernetes.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "cern-it-monitoring-kubernetes.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "cern-it-monitoring-kubernetes.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "cern-it-monitoring-kubernetes.labels" -}} +helm.sh/chart: {{ include "cern-it-monitoring-kubernetes.chart" . }} +{{ include "cern-it-monitoring-kubernetes.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "cern-it-monitoring-kubernetes.selectorLabels" -}} +app.kubernetes.io/name: {{ include "cern-it-monitoring-kubernetes.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} \ No newline at end of file diff --git a/templates/alertmanager/alertmanager.yaml b/templates/alertmanager/alertmanager.yaml index af4e7c6..a423a78 100644 --- a/templates/alertmanager/alertmanager.yaml +++ b/templates/alertmanager/alertmanager.yaml @@ -4,6 +4,8 @@ kind: Alertmanager metadata: name: it-monit-alertmanager namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: image: '{{ .Values.metrics.alertmanager.image }}:{{ .Values.metrics.alertmanager.tag }}' version: {{ .Values.metrics.alertmanager.tag }} diff --git a/templates/alertmanager/ingress.yaml b/templates/alertmanager/ingress.yaml index f912425..aa4a996 100644 --- a/templates/alertmanager/ingress.yaml +++ b/templates/alertmanager/ingress.yaml @@ -5,6 +5,8 @@ kind: Ingress metadata: name: it-monit-alertmanager namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: {{- if .Values.metrics.alertmanager.ingress.className }} ingressClassName: {{ .Values.metrics.alertmanager.ingress.className }} diff --git a/templates/alertmanager/service.yaml b/templates/alertmanager/service.yaml index 272f9bd..a3ae7e8 100644 --- a/templates/alertmanager/service.yaml +++ b/templates/alertmanager/service.yaml @@ -4,6 +4,8 @@ kind: Service metadata: name: it-monit-alertmanager namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: clusterIP: None ports: @@ -11,4 +13,4 @@ spec: port: 9093 selector: app.kubernetes.io/instance: it-monit-alertmanager -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/templates/api_server/servicemonitor.yaml b/templates/api_server/servicemonitor.yaml index fa989ba..dce53e5 100644 --- a/templates/api_server/servicemonitor.yaml +++ b/templates/api_server/servicemonitor.yaml @@ -4,6 +4,8 @@ kind: ServiceMonitor metadata: name: it-monit-metrics-servicemonitor-apiserver namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: endpoints: - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token @@ -37,4 +39,4 @@ spec: matchLabels: component: apiserver provider: kubernetes -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/templates/coredns/servicemonitor.yaml b/templates/coredns/servicemonitor.yaml index 2250f65..920e92e 100644 --- a/templates/coredns/servicemonitor.yaml +++ b/templates/coredns/servicemonitor.yaml @@ -4,6 +4,8 @@ kind: ServiceMonitor metadata: name: it-monit-metrics-servicemonitor-coredns namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: endpoints: - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token @@ -24,4 +26,4 @@ spec: matchLabels: app.kubernetes.io/name: coredns app.kubernetes.io/component: metrics -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/templates/ectd/servicemonitor.yaml b/templates/ectd/servicemonitor.yaml index cd8b9dc..54de9a6 100644 --- a/templates/ectd/servicemonitor.yaml +++ b/templates/ectd/servicemonitor.yaml @@ -4,6 +4,8 @@ kind: ServiceMonitor metadata: name: it-monit-metrics-servicemonitor-etcd namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: endpoints: - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token @@ -24,4 +26,4 @@ spec: matchLabels: app: kube-prometheus-stack-kube-etcd release: cern-magnum -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/templates/fluentbit-logs/clusterrole.yaml b/templates/fluentbit-logs/clusterrole.yaml index 57fe128..8e479ba 100644 --- a/templates/fluentbit-logs/clusterrole.yaml +++ b/templates/fluentbit-logs/clusterrole.yaml @@ -4,6 +4,8 @@ kind: ClusterRole metadata: name: it-monit-logs-collector-fluentbit namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} rules: - apiGroups: - "" diff --git a/templates/fluentbit-logs/clusterrolebinding.yaml b/templates/fluentbit-logs/clusterrolebinding.yaml index 40eec5b..02b69a2 100644 --- a/templates/fluentbit-logs/clusterrolebinding.yaml +++ b/templates/fluentbit-logs/clusterrolebinding.yaml @@ -4,6 +4,8 @@ kind: ClusterRoleBinding metadata: name: it-monit-logs-collector-fluentbit namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole diff --git a/templates/fluentbit-logs/configmap-luascripts.yaml b/templates/fluentbit-logs/configmap-luascripts.yaml index 916c74d..313ec1d 100644 --- a/templates/fluentbit-logs/configmap-luascripts.yaml +++ b/templates/fluentbit-logs/configmap-luascripts.yaml @@ -3,6 +3,8 @@ apiVersion: v1 kind: ConfigMap metadata: name: it-monit-logs-collector-fluentbit-scripts + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} data: time_to_ts.lua: | function add_timestamp_from_time(tag, timestamp, record) @@ -17,4 +19,4 @@ data: {{ $key }}: {{ $value | quote }} {{ end }} {{ end }} -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/templates/fluentbit-logs/configmap.yaml b/templates/fluentbit-logs/configmap.yaml index dc7fb82..d6c8679 100644 --- a/templates/fluentbit-logs/configmap.yaml +++ b/templates/fluentbit-logs/configmap.yaml @@ -4,6 +4,8 @@ kind: ConfigMap metadata: name: it-monit-logs-collector-fluentbit namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} data: custom_parsers.conf: | {{- (tpl .Values.logs.fluentbit.customParsers $) | nindent 4 }} diff --git a/templates/fluentbit-logs/daemonset.yaml b/templates/fluentbit-logs/daemonset.yaml index 31a10c6..1104a45 100644 --- a/templates/fluentbit-logs/daemonset.yaml +++ b/templates/fluentbit-logs/daemonset.yaml @@ -4,6 +4,8 @@ kind: DaemonSet metadata: name: it-monit-logs-collector-fluentbit namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: selector: matchLabels: diff --git a/templates/fluentbit-logs/serviceaccount.yaml b/templates/fluentbit-logs/serviceaccount.yaml index 5f13659..3b1bda3 100644 --- a/templates/fluentbit-logs/serviceaccount.yaml +++ b/templates/fluentbit-logs/serviceaccount.yaml @@ -4,4 +4,6 @@ kind: ServiceAccount metadata: name: it-monit-logs-collector-fluentbit namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} {{- end -}} diff --git a/templates/fluentbit-metrics/configmap-luascripts.yaml b/templates/fluentbit-metrics/configmap-luascripts.yaml index ea6f6a8..e11b4ab 100644 --- a/templates/fluentbit-metrics/configmap-luascripts.yaml +++ b/templates/fluentbit-metrics/configmap-luascripts.yaml @@ -3,10 +3,12 @@ apiVersion: v1 kind: ConfigMap metadata: name: it-monit-metrics-collector-fluentbit-scripts + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} data: {{- if .Values.metrics.fluentbit.luaScripts -}} {{ range $key, $value := .Values.metrics.fluentbit.luaScripts }} {{ $key }}: {{ $value | quote }} {{ end }} {{ end }} -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/templates/fluentbit-metrics/configmap.yaml b/templates/fluentbit-metrics/configmap.yaml index d753bbb..18bfd5a 100644 --- a/templates/fluentbit-metrics/configmap.yaml +++ b/templates/fluentbit-metrics/configmap.yaml @@ -4,6 +4,8 @@ kind: ConfigMap metadata: name: it-monit-metrics-collector-fluentbit namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} data: fluent-bit.yaml: | service: diff --git a/templates/fluentbit-metrics/service.yaml b/templates/fluentbit-metrics/service.yaml index f5f494d..e45fc29 100644 --- a/templates/fluentbit-metrics/service.yaml +++ b/templates/fluentbit-metrics/service.yaml @@ -5,7 +5,7 @@ metadata: name: it-monit-metrics-fluentbit namespace: {{ .Release.Namespace }} labels: - name: it-monit-metrics-collector-fluentbit + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: clusterIP: None ports: diff --git a/templates/fluentbit-metrics/statefulset.yaml b/templates/fluentbit-metrics/statefulset.yaml index 066c236..6fc036a 100644 --- a/templates/fluentbit-metrics/statefulset.yaml +++ b/templates/fluentbit-metrics/statefulset.yaml @@ -4,6 +4,8 @@ kind: StatefulSet metadata: name: it-monit-metrics-collector-fluentbit namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: selector: matchLabels: diff --git a/templates/ingress_nginx/servicemonitor.yaml b/templates/ingress_nginx/servicemonitor.yaml index c06c5ce..400086c 100644 --- a/templates/ingress_nginx/servicemonitor.yaml +++ b/templates/ingress_nginx/servicemonitor.yaml @@ -4,6 +4,8 @@ kind: ServiceMonitor metadata: name: it-monit-metrics-servicemonitor-ingress-nginx namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: endpoints: - interval: 15s diff --git a/templates/kube_state/clusterrole.yaml b/templates/kube_state/clusterrole.yaml index 6ce043c..af53bc1 100644 --- a/templates/kube_state/clusterrole.yaml +++ b/templates/kube_state/clusterrole.yaml @@ -5,7 +5,7 @@ metadata: name: it-monit-metrics-collector-kubestate namespace: {{ .Release.Namespace }} labels: - app.kubernetes.io/name: it-monit-metrics-collector-kubestate + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} rules: - apiGroups: - "" diff --git a/templates/kube_state/clusterrolebinding.yaml b/templates/kube_state/clusterrolebinding.yaml index aec5ec6..75096cf 100644 --- a/templates/kube_state/clusterrolebinding.yaml +++ b/templates/kube_state/clusterrolebinding.yaml @@ -5,7 +5,7 @@ metadata: name: it-monit-metrics-collector-kubestate namespace: {{ .Release.Namespace }} labels: - app.kubernetes.io/name: it-monit-metrics-collector-kubestate + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole diff --git a/templates/kube_state/deployment.yaml b/templates/kube_state/deployment.yaml index 981de6c..b506c48 100644 --- a/templates/kube_state/deployment.yaml +++ b/templates/kube_state/deployment.yaml @@ -5,7 +5,7 @@ metadata: name: it-monit-metrics-collector-kubestate namespace: {{ .Release.Namespace }} labels: - app.kubernetes.io/name: it-monit-metrics-collector-kubestate + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: replicas: 1 selector: diff --git a/templates/kube_state/service.yaml b/templates/kube_state/service.yaml index f76c04a..a5ba53e 100644 --- a/templates/kube_state/service.yaml +++ b/templates/kube_state/service.yaml @@ -5,7 +5,7 @@ metadata: name: it-monit-metrics-collector-kubestate namespace: {{ .Release.Namespace }} labels: - app.kubernetes.io/name: it-monit-metrics-collector-kubestate + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: clusterIP: None ports: diff --git a/templates/kube_state/serviceaccount.yaml b/templates/kube_state/serviceaccount.yaml index c5c101e..72be31b 100644 --- a/templates/kube_state/serviceaccount.yaml +++ b/templates/kube_state/serviceaccount.yaml @@ -6,5 +6,5 @@ metadata: name: it-monit-metrics-collector-kubestate namespace: {{ .Release.Namespace }} labels: - app.kubernetes.io/name: it-monit-metrics-collector-kubestate + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} {{- end -}} diff --git a/templates/kube_state/servicemonitor.yaml b/templates/kube_state/servicemonitor.yaml index 5f9811c..b4ed03c 100644 --- a/templates/kube_state/servicemonitor.yaml +++ b/templates/kube_state/servicemonitor.yaml @@ -4,7 +4,8 @@ kind: ServiceMonitor metadata: name: it-monit-metrics-servicemonitor-kubestate namespace: {{ .Release.Namespace }} - + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: jobLabel: k8s-app endpoints: diff --git a/templates/kubecontroller/servicemonitor.yaml b/templates/kubecontroller/servicemonitor.yaml index 8cd5381..5802cf7 100644 --- a/templates/kubecontroller/servicemonitor.yaml +++ b/templates/kubecontroller/servicemonitor.yaml @@ -4,6 +4,8 @@ kind: ServiceMonitor metadata: name: it-monit-metrics-servicemonitor-kubecontroller namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: endpoints: - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token diff --git a/templates/kubelet/servicemonitor.yaml b/templates/kubelet/servicemonitor.yaml index 6c224f3..697bd17 100644 --- a/templates/kubelet/servicemonitor.yaml +++ b/templates/kubelet/servicemonitor.yaml @@ -4,6 +4,8 @@ kind: ServiceMonitor metadata: name: it-monit-metrics-servicemonitor-kubelet namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: jobLabel: k8s-app endpoints: diff --git a/templates/kubeproxy/servicemonitor.yaml b/templates/kubeproxy/servicemonitor.yaml index 2fb4838..d5ac606 100644 --- a/templates/kubeproxy/servicemonitor.yaml +++ b/templates/kubeproxy/servicemonitor.yaml @@ -4,6 +4,8 @@ kind: ServiceMonitor metadata: name: it-monit-metrics-servicemonitor-kubeproxy namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: endpoints: - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token diff --git a/templates/node_exporter/daemonset.yaml b/templates/node_exporter/daemonset.yaml index 436e7bc..fdd1c36 100644 --- a/templates/node_exporter/daemonset.yaml +++ b/templates/node_exporter/daemonset.yaml @@ -4,6 +4,8 @@ kind: DaemonSet metadata: name: it-monit-metrics-collector-nodeexporter namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: selector: matchLabels: diff --git a/templates/node_exporter/podmonitor.yaml b/templates/node_exporter/podmonitor.yaml index fbf48f7..091ed20 100644 --- a/templates/node_exporter/podmonitor.yaml +++ b/templates/node_exporter/podmonitor.yaml @@ -4,6 +4,8 @@ kind: PodMonitor metadata: name: it-monit-metrics-podmonitor-nodeexporter namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: namespaceSelector: matchNames: diff --git a/templates/prometheus/clusterrole.yaml b/templates/prometheus/clusterrole.yaml index 26b6f9f..d8675a2 100644 --- a/templates/prometheus/clusterrole.yaml +++ b/templates/prometheus/clusterrole.yaml @@ -4,6 +4,8 @@ kind: ClusterRole metadata: name: it-monit-metrics-collector-prometheus namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} rules: - apiGroups: [""] resources: diff --git a/templates/prometheus/clusterrolebinding.yaml b/templates/prometheus/clusterrolebinding.yaml index e038639..e4b70bb 100644 --- a/templates/prometheus/clusterrolebinding.yaml +++ b/templates/prometheus/clusterrolebinding.yaml @@ -4,6 +4,8 @@ kind: ClusterRoleBinding metadata: name: it-monit-metrics-collector-prometheus namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole diff --git a/templates/prometheus/genericservicemonitor.yaml b/templates/prometheus/genericservicemonitor.yaml index 05aa234..527a564 100644 --- a/templates/prometheus/genericservicemonitor.yaml +++ b/templates/prometheus/genericservicemonitor.yaml @@ -8,8 +8,10 @@ kind: ServiceMonitor metadata: name: {{ $t.name }} namespace: {{ $top.Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: {{- toYaml $t.spec | nindent 2 }} {{- end }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/templates/prometheus/prometheus.yaml b/templates/prometheus/prometheus.yaml index b53ca4e..9c3ec15 100644 --- a/templates/prometheus/prometheus.yaml +++ b/templates/prometheus/prometheus.yaml @@ -4,6 +4,8 @@ kind: Prometheus metadata: name: it-monit-metrics-collector-prometheus namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: image: {{ .Values.metrics.prometheus.server.image }} version: {{ .Values.metrics.prometheus.server.version }} diff --git a/templates/prometheus/remotewritesecret.yaml b/templates/prometheus/remotewritesecret.yaml index 59eca9b..f557cdd 100644 --- a/templates/prometheus/remotewritesecret.yaml +++ b/templates/prometheus/remotewritesecret.yaml @@ -4,7 +4,8 @@ apiVersion: v1 kind: Secret metadata: name: it-monit-metrics-collector-prometheus - namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} type: kubernetes.io/basic-auth data: {{- if and .Values.metrics.prometheus.server.remoteWrite.username .Values.metrics.prometheus.server.remoteWrite.password }} diff --git a/templates/prometheus/serviceaccount.yaml b/templates/prometheus/serviceaccount.yaml index 8f46639..8495fc1 100644 --- a/templates/prometheus/serviceaccount.yaml +++ b/templates/prometheus/serviceaccount.yaml @@ -4,4 +4,6 @@ kind: ServiceAccount metadata: name: it-monit-metrics-collector-prometheus namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} {{- end -}} diff --git a/templates/prometheus_operator/clusterrole.yaml b/templates/prometheus_operator/clusterrole.yaml index 22db1ad..870a4d0 100644 --- a/templates/prometheus_operator/clusterrole.yaml +++ b/templates/prometheus_operator/clusterrole.yaml @@ -4,6 +4,8 @@ kind: ClusterRole metadata: name: it-monit-metrics-operator-prometheus namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} rules: - apiGroups: - monitoring.coreos.com diff --git a/templates/prometheus_operator/clusterrolebinding.yaml b/templates/prometheus_operator/clusterrolebinding.yaml index a951431..f0d87ad 100644 --- a/templates/prometheus_operator/clusterrolebinding.yaml +++ b/templates/prometheus_operator/clusterrolebinding.yaml @@ -4,6 +4,8 @@ kind: ClusterRoleBinding metadata: name: it-monit-metrics-operator-prometheus namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole diff --git a/templates/prometheus_operator/deployment.yaml b/templates/prometheus_operator/deployment.yaml index 795efaa..c7631d3 100644 --- a/templates/prometheus_operator/deployment.yaml +++ b/templates/prometheus_operator/deployment.yaml @@ -4,6 +4,8 @@ kind: Deployment metadata: name: it-monit-metrics-operator-prometheus namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: replicas: 1 selector: diff --git a/templates/prometheus_operator/service.yaml b/templates/prometheus_operator/service.yaml index 34e52af..14fa20d 100644 --- a/templates/prometheus_operator/service.yaml +++ b/templates/prometheus_operator/service.yaml @@ -4,6 +4,8 @@ kind: Service metadata: name: it-monit-metrics-operator-prometheus namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: clusterIP: None ports: diff --git a/templates/prometheus_operator/serviceaccount.yaml b/templates/prometheus_operator/serviceaccount.yaml index 969c59e..ebdccad 100644 --- a/templates/prometheus_operator/serviceaccount.yaml +++ b/templates/prometheus_operator/serviceaccount.yaml @@ -5,4 +5,6 @@ kind: ServiceAccount metadata: name: it-monit-metrics-operator-prometheus namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} {{- end -}} diff --git a/templates/pushgateway/deployment.yaml b/templates/pushgateway/deployment.yaml index f36f93f..1d2d40e 100644 --- a/templates/pushgateway/deployment.yaml +++ b/templates/pushgateway/deployment.yaml @@ -5,7 +5,7 @@ metadata: name: it-monit-metrics-collector-pushgateway namespace: {{ .Release.Namespace }} labels: - app.kubernetes.io/name: it-monit-metrics-collector-pushgateway + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: replicas: 1 selector: diff --git a/templates/pushgateway/ingress.yaml b/templates/pushgateway/ingress.yaml index 886f2ee..7b64d8c 100644 --- a/templates/pushgateway/ingress.yaml +++ b/templates/pushgateway/ingress.yaml @@ -5,6 +5,8 @@ kind: Ingress metadata: name: it-monit-metrics-collector-pushgateway namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: {{- if .Values.metrics.pushgateway.ingress.className }} ingressClassName: {{ .Values.metrics.pushgateway.ingress.className }} diff --git a/templates/pushgateway/service.yaml b/templates/pushgateway/service.yaml index 7768dcb..729241c 100644 --- a/templates/pushgateway/service.yaml +++ b/templates/pushgateway/service.yaml @@ -5,7 +5,7 @@ metadata: name: it-monit-metrics-collector-pushgateway namespace: {{ .Release.Namespace }} labels: - app.kubernetes.io/name: it-monit-metrics-collector-pushgateway + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: clusterIP: None ports: diff --git a/templates/pushgateway/servicemonitor.yaml b/templates/pushgateway/servicemonitor.yaml index 44eec39..4ece85c 100644 --- a/templates/pushgateway/servicemonitor.yaml +++ b/templates/pushgateway/servicemonitor.yaml @@ -4,6 +4,8 @@ kind: ServiceMonitor metadata: name: it-monit-metrics-servicemonitor-pushgateway namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: endpoints: - port: http @@ -13,4 +15,4 @@ spec: selector: matchLabels: app.kubernetes.io/name: it-monit-metrics-collector-pushgateway -{{- end -}} \ No newline at end of file +{{- end -}} diff --git a/templates/scheduler/servicemonitor.yaml b/templates/scheduler/servicemonitor.yaml index 954c154..dd7e2a6 100644 --- a/templates/scheduler/servicemonitor.yaml +++ b/templates/scheduler/servicemonitor.yaml @@ -4,6 +4,8 @@ kind: ServiceMonitor metadata: name: servicemonitor-scheduler namespace: {{ .Release.Namespace }} + labels: + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: endpoints: - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token -- GitLab From ab2f8878dbb835f990b084e67822153e33ec768e Mon Sep 17 00:00:00 2001 From: Nacho Barrientos <nacho.barrientos@cern.ch> Date: Wed, 19 Mar 2025 11:10:56 +0100 Subject: [PATCH 2/3] Add missing namespaces --- templates/fluentbit-logs/configmap-luascripts.yaml | 1 + templates/fluentbit-metrics/configmap-luascripts.yaml | 1 + templates/prometheus/remotewritesecret.yaml | 1 + 3 files changed, 3 insertions(+) diff --git a/templates/fluentbit-logs/configmap-luascripts.yaml b/templates/fluentbit-logs/configmap-luascripts.yaml index 313ec1d..b8fad27 100644 --- a/templates/fluentbit-logs/configmap-luascripts.yaml +++ b/templates/fluentbit-logs/configmap-luascripts.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: it-monit-logs-collector-fluentbit-scripts + namespace: {{ .Release.Namespace }} labels: {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} data: diff --git a/templates/fluentbit-metrics/configmap-luascripts.yaml b/templates/fluentbit-metrics/configmap-luascripts.yaml index e11b4ab..db5fd54 100644 --- a/templates/fluentbit-metrics/configmap-luascripts.yaml +++ b/templates/fluentbit-metrics/configmap-luascripts.yaml @@ -3,6 +3,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: it-monit-metrics-collector-fluentbit-scripts + namespace: {{ .Release.Namespace }} labels: {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} data: diff --git a/templates/prometheus/remotewritesecret.yaml b/templates/prometheus/remotewritesecret.yaml index f557cdd..9eb3e0f 100644 --- a/templates/prometheus/remotewritesecret.yaml +++ b/templates/prometheus/remotewritesecret.yaml @@ -4,6 +4,7 @@ apiVersion: v1 kind: Secret metadata: name: it-monit-metrics-collector-prometheus + namespace: {{ .Release.Namespace }} labels: {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} type: kubernetes.io/basic-auth -- GitLab From 34147c8be7fcaa88ecef0d857a289ee9aefb95f6 Mon Sep 17 00:00:00 2001 From: Nacho Barrientos <nacho.barrientos@cern.ch> Date: Fri, 21 Mar 2025 09:26:55 +0100 Subject: [PATCH 3/3] Improve resource selectors --- templates/fluentbit-logs/daemonset.yaml | 5 +++-- templates/fluentbit-metrics/service.yaml | 3 ++- templates/fluentbit-metrics/statefulset.yaml | 8 +++++--- templates/kube_state/deployment.yaml | 6 ++++-- templates/kube_state/service.yaml | 4 +++- templates/kube_state/servicemonitor.yaml | 3 ++- templates/node_exporter/daemonset.yaml | 8 ++++---- templates/node_exporter/podmonitor.yaml | 3 ++- templates/prometheus_operator/deployment.yaml | 6 ++++-- templates/prometheus_operator/service.yaml | 4 ++-- templates/pushgateway/deployment.yaml | 6 ++++-- templates/pushgateway/service.yaml | 4 +++- templates/pushgateway/servicemonitor.yaml | 3 ++- 13 files changed, 40 insertions(+), 23 deletions(-) diff --git a/templates/fluentbit-logs/daemonset.yaml b/templates/fluentbit-logs/daemonset.yaml index 1104a45..d62d574 100644 --- a/templates/fluentbit-logs/daemonset.yaml +++ b/templates/fluentbit-logs/daemonset.yaml @@ -9,13 +9,14 @@ metadata: spec: selector: matchLabels: - name: it-monit-logs-collector-fluentbit + {{- include "cern-it-monitoring-kubernetes.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: fluentbit-logs template: metadata: name: it-monit-logs-collector-fluentbit namespace: {{ .Release.Namespace }} labels: - name: it-monit-logs-collector-fluentbit + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 8 }} spec: serviceAccountName: it-monit-logs-collector-fluentbit containers: diff --git a/templates/fluentbit-metrics/service.yaml b/templates/fluentbit-metrics/service.yaml index e45fc29..372792f 100644 --- a/templates/fluentbit-metrics/service.yaml +++ b/templates/fluentbit-metrics/service.yaml @@ -12,5 +12,6 @@ spec: - name: http port: {{ .Values.metrics.fluentbit.prometheusRemoteWriteInputConfig.port }} selector: - name: it-monit-metrics-collector-fluentbit + {{- include "cern-it-monitoring-kubernetes.selectorLabels" . | nindent 4 }} + app.kubernetes.io/component: fluentbit-metrics {{- end -}} diff --git a/templates/fluentbit-metrics/statefulset.yaml b/templates/fluentbit-metrics/statefulset.yaml index 6fc036a..a3a3e70 100644 --- a/templates/fluentbit-metrics/statefulset.yaml +++ b/templates/fluentbit-metrics/statefulset.yaml @@ -8,15 +8,17 @@ metadata: {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} spec: selector: - matchLabels: - name: it-monit-metrics-collector-fluentbit + matchLabels: + {{- include "cern-it-monitoring-kubernetes.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: fluentbit-metrics replicas: {{ .Values.metrics.fluentbit.replicas }} template: metadata: name: it-monit-metrics-collector-fluentbit namespace: {{ .Release.Namespace }} labels: - name: it-monit-metrics-collector-fluentbit + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 8 }} + app.kubernetes.io/component: fluentbit-metrics spec: containers: - name: it-monit-metrics-collector-fluentbit diff --git a/templates/kube_state/deployment.yaml b/templates/kube_state/deployment.yaml index b506c48..6974a88 100644 --- a/templates/kube_state/deployment.yaml +++ b/templates/kube_state/deployment.yaml @@ -10,11 +10,13 @@ spec: replicas: 1 selector: matchLabels: - app.kubernetes.io/name: it-monit-metrics-collector-kubestate + {{- include "cern-it-monitoring-kubernetes.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: kube-state template: metadata: labels: - app.kubernetes.io/name: it-monit-metrics-collector-kubestate + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 8 }} + app.kubernetes.io/component: kube-state spec: automountServiceAccountToken: true containers: diff --git a/templates/kube_state/service.yaml b/templates/kube_state/service.yaml index a5ba53e..1a1e83f 100644 --- a/templates/kube_state/service.yaml +++ b/templates/kube_state/service.yaml @@ -6,6 +6,7 @@ metadata: namespace: {{ .Release.Namespace }} labels: {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} + app.kubernetes.io/component: kube-state spec: clusterIP: None ports: @@ -16,5 +17,6 @@ spec: port: 8081 targetPort: telemetry selector: - app.kubernetes.io/name: it-monit-metrics-collector-kubestate + {{- include "cern-it-monitoring-kubernetes.selectorLabels" . | nindent 4 }} + app.kubernetes.io/component: kube-state {{- end -}} diff --git a/templates/kube_state/servicemonitor.yaml b/templates/kube_state/servicemonitor.yaml index b4ed03c..e6d0d8b 100644 --- a/templates/kube_state/servicemonitor.yaml +++ b/templates/kube_state/servicemonitor.yaml @@ -26,7 +26,8 @@ spec: {{- end }} selector: matchLabels: - app.kubernetes.io/name: "it-monit-metrics-collector-kubestate" + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 6 }} + app.kubernetes.io/component: kube-state namespaceSelector: matchNames: - {{ .Release.Namespace }} diff --git a/templates/node_exporter/daemonset.yaml b/templates/node_exporter/daemonset.yaml index fdd1c36..e553d12 100644 --- a/templates/node_exporter/daemonset.yaml +++ b/templates/node_exporter/daemonset.yaml @@ -9,13 +9,13 @@ metadata: spec: selector: matchLabels: - app.kubernetes.io/component: exporter - app.kubernetes.io/name: node-exporter + {{- include "cern-it-monitoring-kubernetes.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: node-exporter template: metadata: labels: - app.kubernetes.io/component: exporter - app.kubernetes.io/name: node-exporter + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 8 }} + app.kubernetes.io/component: node-exporter spec: tolerations: - operator: Exists diff --git a/templates/node_exporter/podmonitor.yaml b/templates/node_exporter/podmonitor.yaml index 091ed20..6e049e7 100644 --- a/templates/node_exporter/podmonitor.yaml +++ b/templates/node_exporter/podmonitor.yaml @@ -12,7 +12,8 @@ spec: - {{ .Release.Namespace }} selector: matchLabels: - app.kubernetes.io/name: node-exporter + {{- include "cern-it-monitoring-kubernetes.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: node-exporter podMetricsEndpoints: - targetPort: 9100 {{- if .Values.metrics.nodeExporter.scrapeInterval }} diff --git a/templates/prometheus_operator/deployment.yaml b/templates/prometheus_operator/deployment.yaml index c7631d3..d7a3120 100644 --- a/templates/prometheus_operator/deployment.yaml +++ b/templates/prometheus_operator/deployment.yaml @@ -10,13 +10,15 @@ spec: replicas: 1 selector: matchLabels: - app.kubernetes.io/name: it-monit-metrics-operator-prometheus + {{- include "cern-it-monitoring-kubernetes.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: prometheus-operator template: metadata: annotations: kubectl.kubernetes.io/default-container: it-monit-metrics-operator-prometheus labels: - app.kubernetes.io/name: it-monit-metrics-operator-prometheus + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 8 }} + app.kubernetes.io/component: prometheus-operator spec: automountServiceAccountToken: true containers: diff --git a/templates/prometheus_operator/service.yaml b/templates/prometheus_operator/service.yaml index 14fa20d..f18294a 100644 --- a/templates/prometheus_operator/service.yaml +++ b/templates/prometheus_operator/service.yaml @@ -13,6 +13,6 @@ spec: port: 8080 targetPort: http selector: - app.kubernetes.io/component: controller - app.kubernetes.io/name: it-monit-metrics-operator-prometheus + {{- include "cern-it-monitoring-kubernetes.selectorLabels" . | nindent 4 }} + app.kubernetes.io/component: prometheus-operator {{- end -}} diff --git a/templates/pushgateway/deployment.yaml b/templates/pushgateway/deployment.yaml index 1d2d40e..be058bd 100644 --- a/templates/pushgateway/deployment.yaml +++ b/templates/pushgateway/deployment.yaml @@ -10,11 +10,13 @@ spec: replicas: 1 selector: matchLabels: - app.kubernetes.io/name: it-monit-metrics-collector-pushgateway + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 6 }} + app.kubernetes.io/component: pushgateway template: metadata: labels: - app.kubernetes.io/name: it-monit-metrics-collector-pushgateway + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 8 }} + app.kubernetes.io/component: pushgateway spec: containers: - image: "{{ .Values.metrics.pushgateway.image.repository }}:{{ .Values.metrics.pushgateway.image.tag }}" diff --git a/templates/pushgateway/service.yaml b/templates/pushgateway/service.yaml index 729241c..98221d5 100644 --- a/templates/pushgateway/service.yaml +++ b/templates/pushgateway/service.yaml @@ -6,11 +6,13 @@ metadata: namespace: {{ .Release.Namespace }} labels: {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} + app.kubernetes.io/component: pushgateway spec: clusterIP: None ports: - name: http port: 9091 selector: - app.kubernetes.io/name: it-monit-metrics-collector-pushgateway + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 4 }} + app.kubernetes.io/component: pushgateway {{- end -}} diff --git a/templates/pushgateway/servicemonitor.yaml b/templates/pushgateway/servicemonitor.yaml index 4ece85c..bff7d57 100644 --- a/templates/pushgateway/servicemonitor.yaml +++ b/templates/pushgateway/servicemonitor.yaml @@ -14,5 +14,6 @@ spec: - {{ .Release.Namespace }} selector: matchLabels: - app.kubernetes.io/name: it-monit-metrics-collector-pushgateway + {{- include "cern-it-monitoring-kubernetes.labels" . | nindent 6 }} + app.kubernetes.io/component: pushgateway {{- end -}} -- GitLab