From 991517ae0e40cf8620d6e3412f228343b856f57d Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Thu, 2 Nov 2023 11:48:58 +0100 Subject: [PATCH] Updated template chart --- argocd/prometheus/test/argocd_values.yaml | 2 +- helm/template/Chart.yaml | 6 +++--- helm/template/_templates/podmonitor.yaml | 1 + helm/template/_values.yaml | 5 +++++ helm/template/templates/_deployment.yaml | 6 +----- helm/template/templates/_podmonitor.yaml | 17 +++++++++++++++++ 6 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 helm/template/_templates/podmonitor.yaml create mode 100644 helm/template/templates/_podmonitor.yaml diff --git a/argocd/prometheus/test/argocd_values.yaml b/argocd/prometheus/test/argocd_values.yaml index d1727be..fd3ee69 100644 --- a/argocd/prometheus/test/argocd_values.yaml +++ b/argocd/prometheus/test/argocd_values.yaml @@ -25,4 +25,4 @@ kube-prometheus-stack: - 10.0.0.2 kubeScheduler: endpoints: - - 10.0.0.2 \ No newline at end of file + - 10.0.0.2 diff --git a/helm/template/Chart.yaml b/helm/template/Chart.yaml index bbdb956..60199a0 100644 --- a/helm/template/Chart.yaml +++ b/helm/template/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: template description: A Helm library chart containing common templates, keeping application templates short type: library -version: 0.1.19 +version: 0.1.20 maintainers: - name: Jim Martens url: https://2martens.de @@ -10,8 +10,8 @@ sources: - https://git.2martens.de/2martens/cloud-configuration annotations: artifacthub.io/changes: | - - kind: fixed - description: Fixed annotations + - kind: changed + description: Added support for Prometheus operator with pod monitor artifacthub.io/signKey: | fingerprint: F0F153B65BAD467201D7544E47393ABD1F96B7C8 url: https://mafiasi.de/pks/key/47393ABD1F96B7C8.asc diff --git a/helm/template/_templates/podmonitor.yaml b/helm/template/_templates/podmonitor.yaml new file mode 100644 index 0000000..b446789 --- /dev/null +++ b/helm/template/_templates/podmonitor.yaml @@ -0,0 +1 @@ +{{- include "template.podmonitor" . -}} diff --git a/helm/template/_values.yaml b/helm/template/_values.yaml index 27f9195..31b6d4e 100644 --- a/helm/template/_values.yaml +++ b/helm/template/_values.yaml @@ -56,6 +56,11 @@ application: prometheus: enabled: true + # only enable if you have the Prometheus operator installed, otherwise it will fail due to missing CRDs + useCRDs: false + # namespace: the namespace of the Prometheus installation + # the value is templated + namespace: # Overwrite with application specific environment variables # Each item has key and value, where the value is parsed as a template diff --git a/helm/template/templates/_deployment.yaml b/helm/template/templates/_deployment.yaml index 186892a..f32af2a 100644 --- a/helm/template/templates/_deployment.yaml +++ b/helm/template/templates/_deployment.yaml @@ -16,13 +16,9 @@ spec: template: metadata: annotations: - {{- if $.Values.prometheus.enabled }} + {{- if and $.Values.prometheus.enabled (not $.Values.prometheus.useCRDs) $.Values.application.isSpring }} prometheus.io/scrape: "true" - {{- if $.Values.application.isSpring }} prometheus.io/path: /actuator/prometheus - {{- else }} - prometheus.io/path: /metrics - {{- end }} prometheus.io/port: "{{ $.Values.application.actuatorPort }}" {{- end }} {{- with .Values.podAnnotations }} diff --git a/helm/template/templates/_podmonitor.yaml b/helm/template/templates/_podmonitor.yaml new file mode 100644 index 0000000..3889714 --- /dev/null +++ b/helm/template/templates/_podmonitor.yaml @@ -0,0 +1,17 @@ +{{- define "template.podmonitor" -}} +{{- if and .Values.prometheus.enabled .Values.prometheus.useCRDs .Values.application.isSpring }} +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ include "template.fullname" . }} + namespace: {{ tpl .Values.prometheus.namespace . | default "observability" }} + labels: + {{- include "template.labels" . | nindent 4 }} +spec: + podMetricsEndpoints: + - port: {{ .Values.application.actuatorPort }} + path: /actuator/prometheus + selector: + {{- include "template.selectorLabels" . | nindent 4 }} +{{- end }} +{{- end }}