From ab789909c88739963f14d0a3b02a9ba1cbab96a4 Mon Sep 17 00:00:00 2001 From: Kevin Lefevre Date: Wed, 11 Sep 2024 21:41:21 +0200 Subject: [PATCH] feat: add ServiceMonitor support to helm chart (#114) * Scrape metrics automatically when using Prometheus operator Signed-off-by: Kevin Lefevre --- .../templates/servicemonitor.yaml | 41 +++++++++++++++++++ k8s/commit-boost/values.yaml | 27 ++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 k8s/commit-boost/templates/servicemonitor.yaml diff --git a/k8s/commit-boost/templates/servicemonitor.yaml b/k8s/commit-boost/templates/servicemonitor.yaml new file mode 100644 index 00000000..c5bb5add --- /dev/null +++ b/k8s/commit-boost/templates/servicemonitor.yaml @@ -0,0 +1,41 @@ +{{- if .Values.serviceMonitor.enabled -}} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "commit-boost.fullname" . }} +{{- if .Values.serviceMonitor.namespace }} + namespace: {{ .Values.serviceMonitor.namespace | quote }} +{{- end }} + labels: + {{- include "commit-boost.labels" . | nindent 4 }} + {{- if .Values.serviceMonitor.additionalLabels }} + {{- toYaml .Values.serviceMonitor.additionalLabels | nindent 4 }} + {{- end }} +spec: + endpoints: + - port: http-metrics + interval: {{ .Values.serviceMonitor.scrapeInterval }} + {{- if .Values.serviceMonitor.honorLabels }} + honorLabels: true + {{- end }} + {{- if .Values.serviceMonitor.metricRelabelings }} + metricRelabelings: {{ toYaml .Values.serviceMonitor.metricRelabelings | nindent 8 }} + {{- end }} + path: {{ .Values.serviceMonitor.path }} +{{- if .Values.serviceMonitor.namespaceSelector }} + namespaceSelector: {{ toYaml .Values.serviceMonitor.namespaceSelector | nindent 4 }} +{{ else }} + namespaceSelector: + matchNames: + - {{ .Release.Namespace }} +{{- end }} +{{- if .Values.serviceMonitor.targetLabels }} + targetLabels: + {{- range .Values.serviceMonitor.targetLabels }} + - {{ . }} + {{- end }} +{{- end }} + selector: + matchLabels: + {{- include "commit-boost.selectorLabels" . | nindent 6 }} +{{- end }} diff --git a/k8s/commit-boost/values.yaml b/k8s/commit-boost/values.yaml index 8aed5a4f..90a254b9 100644 --- a/k8s/commit-boost/values.yaml +++ b/k8s/commit-boost/values.yaml @@ -27,10 +27,12 @@ serviceAccount: podAnnotations: {} podLabels: {} -podSecurityContext: {} +podSecurityContext: + {} # fsGroup: 2000 -securityContext: {} +securityContext: + {} # capabilities: # drop: # - ALL @@ -46,7 +48,8 @@ service: ingress: enabled: false className: "" - annotations: {} + annotations: + {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" hosts: @@ -59,7 +62,8 @@ ingress: # hosts: # - chart-example.local -resources: {} +resources: + {} # We usually recommend not to specify default resources and to leave this as a conscious # choice for the user. This also increases chances charts run on environments with little # resources, such as Minikube. If you do want to specify resources, uncomment the following @@ -97,6 +101,21 @@ tolerations: [] affinity: {} +serviceMonitor: + enabled: false + additionalLabels: {} + namespace: "" + namespaceSelector: {} + # Default: scrape .Release.Namespace only + # To scrape all, use the following: + # namespaceSelector: + # any: true + scrapeInterval: 30s + # honorLabels: true + targetLabels: [] + metricRelabelings: [] + # path: /metrics + commitBoost: pbs: enable: true