helm-charts/charts/library/common/templates/classes/_serviceMonitor.tpl
Bernd Schorgers 4a5f448abd
feat(common): Release 3.2.0 (#318)
Signed-off-by: Gavin Mogan <git@gavinmogan.com>
Co-authored-by: Gavin Mogan <git@gavinmogan.com>
Co-authored-by: repo-duster[bot] <87358111+repo-duster[bot]@users.noreply.github.com>
2024-05-23 09:54:12 +00:00

47 lines
1.6 KiB
Smarty

{{- define "bjw-s.common.class.serviceMonitor" -}}
{{- $rootContext := .rootContext -}}
{{- $serviceMonitorObject := .object -}}
{{- $labels := merge
($serviceMonitorObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
-}}
{{- $annotations := merge
($serviceMonitorObject.annotations | default dict)
(include "bjw-s.common.lib.metadata.globalAnnotations" $rootContext | fromYaml)
-}}
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ $serviceMonitorObject.name }}
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{ $key }}: {{ tpl $value $rootContext }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{ $key }}: {{ tpl $value $rootContext }}
{{- end }}
{{- end }}
spec:
jobLabel: "{{ $serviceMonitorObject.name }}"
namespaceSelector:
matchNames:
- {{ $rootContext.Release.Namespace }}
selector:
{{- if $serviceMonitorObject.selector -}}
{{- tpl ($serviceMonitorObject.selector | toYaml) $rootContext | nindent 4}}
{{- else }}
matchLabels:
app.kubernetes.io/service: {{ tpl $serviceMonitorObject.serviceName $rootContext }}
{{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }}
{{- end }}
endpoints: {{- toYaml $serviceMonitorObject.endpoints | nindent 4 }}
{{- if not (empty $serviceMonitorObject.targetLabels )}}
targetLabels:
{{- toYaml $serviceMonitorObject.targetLabels | nindent 4 }}
{{- end }}
{{- end }}