From ca268b4346995da9d88755410e68e0c78bd2ea3f Mon Sep 17 00:00:00 2001 From: Wilfried ROSET Date: Wed, 30 Oct 2024 17:25:16 +0100 Subject: [PATCH] [prometheus-sql-exporter] Fix labels/matchLabels (#4947) * [prometheus-sql-exporter] Fix labels/matchLabels by using include instead of duplicating declaration in each file Signed-off-by: Wilfried Roset * [prometheus-sql-exporter] Raises the minor version as the old-style labels are replaced Signed-off-by: Wilfried Roset * [prometheus-sql-exporter] Adjust NOTES.txt to take into account correct label name Signed-off-by: Wilfried Roset --------- Signed-off-by: Wilfried Roset --- charts/prometheus-sql-exporter/Chart.yaml | 2 +- .../prometheus-sql-exporter/templates/NOTES.txt | 2 +- .../templates/deployment.yaml | 15 +++++---------- .../templates/networkpolicy.yaml | 3 +-- charts/prometheus-sql-exporter/templates/pdb.yaml | 8 ++------ .../templates/prometheusrule.yaml | 5 +---- .../prometheus-sql-exporter/templates/role.yaml | 5 +---- .../templates/rolebinding.yaml | 5 +---- .../templates/service.yaml | 8 ++------ .../templates/serviceaccount.yaml | 5 +---- .../templates/servicemonitor.yaml | 3 +-- 11 files changed, 17 insertions(+), 44 deletions(-) diff --git a/charts/prometheus-sql-exporter/Chart.yaml b/charts/prometheus-sql-exporter/Chart.yaml index 722d8d35d6d5..0722b57e4db4 100644 --- a/charts/prometheus-sql-exporter/Chart.yaml +++ b/charts/prometheus-sql-exporter/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 description: Prometheus SQL Exporter name: prometheus-sql-exporter -version: 0.1.2 +version: 0.2.0 appVersion: v0.5.8 home: https://github.com/justwatchcom/sql_exporter sources: diff --git a/charts/prometheus-sql-exporter/templates/NOTES.txt b/charts/prometheus-sql-exporter/templates/NOTES.txt index e83d522b6eb2..836b549c8bd4 100644 --- a/charts/prometheus-sql-exporter/templates/NOTES.txt +++ b/charts/prometheus-sql-exporter/templates/NOTES.txt @@ -9,7 +9,7 @@ export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "prometheus-sql-exporter.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') echo http://$SERVICE_IP:{{ .Values.service.port }} {{- else if contains "ClusterIP" .Values.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "prometheus-sql-exporter.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ template "prometheus-sql-exporter.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl port-forward $POD_NAME 8080:9187 {{- end }} diff --git a/charts/prometheus-sql-exporter/templates/deployment.yaml b/charts/prometheus-sql-exporter/templates/deployment.yaml index c08cec753ec2..a99b429f0f4a 100644 --- a/charts/prometheus-sql-exporter/templates/deployment.yaml +++ b/charts/prometheus-sql-exporter/templates/deployment.yaml @@ -3,24 +3,19 @@ kind: Deployment metadata: name: {{ template "prometheus-sql-exporter.fullname" . }} labels: - app: {{ template "prometheus-sql-exporter.name" . }} - chart: {{ template "prometheus-sql-exporter.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + {{- include "prometheus-sql-exporter.labels" . | nindent 4 }} spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: - app: {{ template "prometheus-sql-exporter.name" . }} - release: {{ .Release.Name }} + {{- include "prometheus-sql-exporter.selectorLabels" . | nindent 6 }} template: metadata: labels: - app: {{ template "prometheus-sql-exporter.name" . }} - release: {{ .Release.Name }} -{{- if .Values.podLabels }} + {{- include "prometheus-sql-exporter.selectorLabels" . | nindent 8 }} + {{- if .Values.podLabels }} {{ toYaml .Values.podLabels | trim | indent 8 }} -{{- end }} + {{- end }} annotations: kubectl.kubernetes.io/default-container: {{ .Chart.Name }} {{- if .Values.annotations }} diff --git a/charts/prometheus-sql-exporter/templates/networkpolicy.yaml b/charts/prometheus-sql-exporter/templates/networkpolicy.yaml index 1ee1281cb8c9..1fd56bfa6a01 100644 --- a/charts/prometheus-sql-exporter/templates/networkpolicy.yaml +++ b/charts/prometheus-sql-exporter/templates/networkpolicy.yaml @@ -10,8 +10,7 @@ metadata: spec: podSelector: matchLabels: - app: {{ template "prometheus-sql-exporter.name" . }} - release: {{ .Release.Name }} + {{- include "prometheus-sql-exporter.selectorLabels" . | nindent 8 }} policyTypes: - Ingress ingress: diff --git a/charts/prometheus-sql-exporter/templates/pdb.yaml b/charts/prometheus-sql-exporter/templates/pdb.yaml index 9b759bf08729..2c27af941eee 100644 --- a/charts/prometheus-sql-exporter/templates/pdb.yaml +++ b/charts/prometheus-sql-exporter/templates/pdb.yaml @@ -4,14 +4,10 @@ kind: PodDisruptionBudget metadata: name: {{ template "prometheus-sql-exporter.fullname" . }} labels: - app: {{ template "prometheus-sql-exporter.name" . }} - chart: {{ template "prometheus-sql-exporter.chart" . }} - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + {{- include "prometheus-sql-exporter.selectorLabels" . | nindent 8 }} spec: maxUnavailable: {{ .Values.podDisruptionBudget.maxUnavailable }} selector: matchLabels: - app: {{ template "prometheus-sql-exporter.name" . }} - release: {{ .Release.Name }} + {{- include "prometheus-sql-exporter.selectorLabels" . | nindent 8 }} {{- end }} diff --git a/charts/prometheus-sql-exporter/templates/prometheusrule.yaml b/charts/prometheus-sql-exporter/templates/prometheusrule.yaml index 13228d42f94d..d7f319f0ed63 100644 --- a/charts/prometheus-sql-exporter/templates/prometheusrule.yaml +++ b/charts/prometheus-sql-exporter/templates/prometheusrule.yaml @@ -7,10 +7,7 @@ metadata: namespace: {{ . }} {{- end }} labels: - app: {{ template "prometheus-sql-exporter.name" . }} - chart: {{ template "prometheus-sql-exporter.chart" . }} - release: {{ .Release.Name | quote }} - heritage: {{ .Release.Service | quote }} + {{- include "prometheus-sql-exporter.labels" . | nindent 4 }} {{- with .Values.prometheusRule.additionalLabels }} {{ toYaml . | indent 4 }} {{- end }} diff --git a/charts/prometheus-sql-exporter/templates/role.yaml b/charts/prometheus-sql-exporter/templates/role.yaml index 9fa8b11bd42d..7889db2f6a83 100644 --- a/charts/prometheus-sql-exporter/templates/role.yaml +++ b/charts/prometheus-sql-exporter/templates/role.yaml @@ -4,10 +4,7 @@ kind: Role metadata: name: {{ template "prometheus-sql-exporter.fullname" . }} labels: - app: {{ template "prometheus-sql-exporter.name" . }} - chart: {{ template "prometheus-sql-exporter.chart" . }} - heritage: {{ .Release.Service }} - release: {{ .Release.Name }} + {{- include "prometheus-sql-exporter.labels" . | nindent 4 }} {{- if .Values.rbac.pspEnabled }} rules: - apiGroups: ['extensions'] diff --git a/charts/prometheus-sql-exporter/templates/rolebinding.yaml b/charts/prometheus-sql-exporter/templates/rolebinding.yaml index 424b77fc5e9e..c520c855f149 100644 --- a/charts/prometheus-sql-exporter/templates/rolebinding.yaml +++ b/charts/prometheus-sql-exporter/templates/rolebinding.yaml @@ -4,10 +4,7 @@ kind: RoleBinding metadata: name: {{ template "prometheus-sql-exporter.fullname" . }} labels: - app: {{ template "prometheus-sql-exporter.name" . }} - chart: {{ template "prometheus-sql-exporter.chart" . }} - heritage: {{ .Release.Service }} - release: {{ .Release.Name }} + {{- include "prometheus-sql-exporter.labels" . | nindent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: Role diff --git a/charts/prometheus-sql-exporter/templates/service.yaml b/charts/prometheus-sql-exporter/templates/service.yaml index 4f04d717fa2d..fb74f6ccd4ae 100644 --- a/charts/prometheus-sql-exporter/templates/service.yaml +++ b/charts/prometheus-sql-exporter/templates/service.yaml @@ -7,10 +7,7 @@ metadata: {{ toYaml .Values.service.annotations | indent 4 }} {{- end }} labels: - app: {{ template "prometheus-sql-exporter.name" . }} - chart: {{ template "prometheus-sql-exporter.chart" . }} - release: {{ .Release.Name }} - heritage: {{ .Release.Service }} + {{- include "prometheus-sql-exporter.labels" . | nindent 4 }} {{- if .Values.service.labels }} {{ toYaml .Values.service.labels | trim | indent 4 }} {{- end }} @@ -22,5 +19,4 @@ spec: protocol: TCP name: {{ .Values.service.name }} selector: - app: {{ template "prometheus-sql-exporter.name" . }} - release: {{ .Release.Name }} + {{- include "prometheus-sql-exporter.selectorLabels" . | nindent 8 }} diff --git a/charts/prometheus-sql-exporter/templates/serviceaccount.yaml b/charts/prometheus-sql-exporter/templates/serviceaccount.yaml index 1757c901d922..a87564fc2e22 100644 --- a/charts/prometheus-sql-exporter/templates/serviceaccount.yaml +++ b/charts/prometheus-sql-exporter/templates/serviceaccount.yaml @@ -4,10 +4,7 @@ kind: ServiceAccount metadata: name: {{ template "prometheus-sql-exporter.serviceAccountName" . }} labels: - app: {{ template "prometheus-sql-exporter.name" . }} - chart: {{ template "prometheus-sql-exporter.chart" . }} - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + {{- include "prometheus-sql-exporter.labels" . | nindent 4 }} {{- if .Values.serviceAccount.annotations }} annotations: {{ toYaml .Values.serviceAccount.annotations }} diff --git a/charts/prometheus-sql-exporter/templates/servicemonitor.yaml b/charts/prometheus-sql-exporter/templates/servicemonitor.yaml index 518b08a66951..90b24387e841 100644 --- a/charts/prometheus-sql-exporter/templates/servicemonitor.yaml +++ b/charts/prometheus-sql-exporter/templates/servicemonitor.yaml @@ -36,8 +36,7 @@ spec: - {{ .Release.Namespace }} selector: matchLabels: - app: {{ template "prometheus-sql-exporter.name" . }} - release: {{ .Release.Name }} + {{- include "prometheus-sql-exporter.selectorLabels" . | nindent 8 }} {{- if .Values.serviceMonitor.targetLabels }} targetLabels: {{- range .Values.serviceMonitor.targetLabels }}