From c87cee4deb401da2f88c65c60c97dd9b7044df92 Mon Sep 17 00:00:00 2001 From: Starttoaster Date: Wed, 12 Jun 2024 15:30:53 -0700 Subject: [PATCH] Add optional ServiceMonitor to the generic chart --- charts/generic/Chart.yaml | 2 +- charts/generic/templates/servicemonitor.yaml | 43 ++++++++++++++++++++ charts/generic/values.yaml | 18 ++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 charts/generic/templates/servicemonitor.yaml diff --git a/charts/generic/Chart.yaml b/charts/generic/Chart.yaml index 5c3d455..c9f2f1c 100644 --- a/charts/generic/Chart.yaml +++ b/charts/generic/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v2 name: generic description: A generic helm chart that handles a bunch of common application deploy cases type: application -version: 1.10.0 +version: 1.11.0 diff --git a/charts/generic/templates/servicemonitor.yaml b/charts/generic/templates/servicemonitor.yaml new file mode 100644 index 0000000..3c07f8d --- /dev/null +++ b/charts/generic/templates/servicemonitor.yaml @@ -0,0 +1,43 @@ +{{- if .Values.serviceMonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "generic.fullname" . }} + labels: + {{- include "generic.labels" . | nindent 4 }} + {{- if .Values.serviceMonitor.additionalLabels }} + {{- toYaml .Values.serviceMonitor.additionalLabels | nindent 4 }} + {{- end }} + {{- if .Values.serviceMonitor.annotations }} + annotations: {{ toYaml .Values.serviceMonitor.annotations | nindent 4 }} + {{- end }} +spec: + endpoints: + - interval: 30s + port: {{ .Values.serviceMonitor.endpointPort }} + {{- if .Values.serviceMonitor.relabelings }} + relabelings: {{ toYaml .Values.serviceMonitor.relabelings | nindent 8 }} + {{- end }} + {{- if .Values.serviceMonitor.metricRelabelings }} + metricRelabelings: {{ toYaml .Values.serviceMonitor.metricRelabelings | nindent 8 }} + {{- end }} +{{- if .Values.serviceMonitor.namespaceSelector }} + namespaceSelector: {{ toYaml .Values.serviceMonitor.namespaceSelector | nindent 4 }} +{{- else }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} +{{- end }} +{{- if .Values.serviceMonitor.jobLabel }} + jobLabel: {{ .Values.serviceMonitor.jobLabel | quote }} +{{- end }} +{{- if .Values.serviceMonitor.targetLabels }} + targetLabels: + {{- range .Values.serviceMonitor.targetLabels }} + - {{ . }} + {{- end }} +{{- end }} + selector: + matchLabels: + {{- include "generic.labels" . | nindent 6 }} +{{- end }} diff --git a/charts/generic/values.yaml b/charts/generic/values.yaml index fe5bff3..c499014 100644 --- a/charts/generic/values.yaml +++ b/charts/generic/values.yaml @@ -148,6 +148,24 @@ networkPolicy: # - protocol: TCP # port: 8555 +serviceMonitor: + enabled: false + # Changes the servicemonitor's spec.endpoints[0].port + # Can be a port number or name + endpointPort: metrics + ## The label to use to retrieve the job name from. + ## jobLabel: "app.kubernetes.io/name" + additionalLabels: {} + annotations: {} + namespaceSelector: {} + ## Default: scrape .Release.Namespace or namespaceOverride only + ## To scrape all, use the following: + ## namespaceSelector: + ## any: true + targetLabels: [] + relabelings: [] + metricRelabelings: [] + # Creates a secret with the following values, and mounts as env into the main deployment container secretEnvironment: {} # MY_KEY: "My Value"