From 41b336b40a0e5595edb590bbb346c69e29355ae0 Mon Sep 17 00:00:00 2001 From: ShlomiTubul Date: Sun, 25 Feb 2024 00:16:25 +0200 Subject: [PATCH] Add support for PodMonitor Signed-off-by: ShlomiTubul --- .../templates/metrics-podmonitor.yaml | 35 ++++++++++++ .../charts/trust-manager/values.schema.json | 57 +++++++++++++++++++ deploy/charts/trust-manager/values.yaml | 20 ++++++- 3 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 deploy/charts/trust-manager/templates/metrics-podmonitor.yaml diff --git a/deploy/charts/trust-manager/templates/metrics-podmonitor.yaml b/deploy/charts/trust-manager/templates/metrics-podmonitor.yaml new file mode 100644 index 00000000..04498ac7 --- /dev/null +++ b/deploy/charts/trust-manager/templates/metrics-podmonitor.yaml @@ -0,0 +1,35 @@ +{{- if and .Values.app.metrics.podmonitor.enabled .Values.app.metrics.service.servicemonitor.enabled }} +{{- fail "Either .Values.app.metrics.podmonitor.enabled or .Values.app.metrics.service.servicemonitor.enabled can be enabled at a time, but not both." }} +{{- else if .Values.app.metrics.podmonitor.enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: PodMonitor +metadata: + name: {{ include "trust-manager.name" . }} + namespace: {{ include "trust-manager.namespace" . }} + labels: + app: {{ include "trust-manager.name" . }} +{{ include "trust-manager.labels" . | indent 4 }} + prometheus: {{ .Values.app.metrics.podmonitor.prometheusInstance }} +{{- if .Values.app.metrics.podmonitor.labels }} +{{ toYaml .Values.app.metrics.podmonitor.labels | indent 4}} +{{- end }} +{{- if .Values.app.metrics.podmonitor.annotations }} + annotations: + {{- with .Values.app.metrics.podmonitor.annotations }} + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} +spec: + jobLabel: {{ include "trust-manager.name" . }} + selector: + matchLabels: + app: {{ include "trust-manager.name" . }} + namespaceSelector: + matchNames: + - {{ include "trust-manager.namespace" . }} + podMetricsEndpoints: + - port: {{ .Values.app.metrics.port }} + path: "/metrics" + interval: {{ .Values.app.metrics.podmonitor.interval }} + scrapeTimeout: {{ .Values.app.metrics.podmonitor.scrapeTimeout }} +{{- end }} \ No newline at end of file diff --git a/deploy/charts/trust-manager/values.schema.json b/deploy/charts/trust-manager/values.schema.json index d7d22165..85af2bad 100644 --- a/deploy/charts/trust-manager/values.schema.json +++ b/deploy/charts/trust-manager/values.schema.json @@ -99,6 +99,9 @@ "helm-values.app.metrics": { "type": "object", "properties": { + "podmonitor": { + "$ref": "#/$defs/helm-values.app.metrics.podmonitor" + }, "port": { "$ref": "#/$defs/helm-values.app.metrics.port" }, @@ -108,6 +111,60 @@ }, "additionalProperties": false }, + "helm-values.app.metrics.podmonitor": { + "type": "object", + "properties": { + "annotations": { + "$ref": "#/$defs/helm-values.app.metrics.podmonitor.annotations" + }, + "enabled": { + "$ref": "#/$defs/helm-values.app.metrics.podmonitor.enabled" + }, + "interval": { + "$ref": "#/$defs/helm-values.app.metrics.podmonitor.interval" + }, + "labels": { + "$ref": "#/$defs/helm-values.app.metrics.podmonitor.labels" + }, + "prometheusInstance": { + "$ref": "#/$defs/helm-values.app.metrics.podmonitor.prometheusInstance" + }, + "scrapeTimeout": { + "$ref": "#/$defs/helm-values.app.metrics.podmonitor.scrapeTimeout" + } + }, + "additionalProperties": false + }, + "helm-values.app.metrics.podmonitor.annotations": { + "description": "Additional annotations to add to the PodMonitor.", + "type": "object", + "default": {} + }, + "helm-values.app.metrics.podmonitor.enabled": { + "description": "The PodMonitor resource for this Service.", + "type": "boolean", + "default": false + }, + "helm-values.app.metrics.podmonitor.interval": { + "description": "The interval to scrape metrics.", + "type": "string", + "default": "10s" + }, + "helm-values.app.metrics.podmonitor.labels": { + "description": "Additional labels to add to the PodMonitor.", + "type": "object", + "default": {} + }, + "helm-values.app.metrics.podmonitor.prometheusInstance": { + "description": "Specifies the `prometheus` label on the created PodMonitor. This is used when different Prometheus instances have label selectors matching different PodMonitors.", + "type": "string", + "default": "default" + }, + "helm-values.app.metrics.podmonitor.scrapeTimeout": { + "description": "The timeout before a metrics scrape fails.", + "type": "string", + "default": "5s" + }, "helm-values.app.metrics.port": { "description": "The port for exposing Prometheus metrics on 0.0.0.0 on path '/metrics'.", "type": "number", diff --git a/deploy/charts/trust-manager/values.yaml b/deploy/charts/trust-manager/values.yaml index 977ff38f..13bffae8 100644 --- a/deploy/charts/trust-manager/values.yaml +++ b/deploy/charts/trust-manager/values.yaml @@ -185,7 +185,7 @@ app: port: 6443 # Timeout of webhook HTTP request. timeoutSeconds: 5 - + service: # The type of Kubernetes Service used by the Webhook. type: ClusterIP @@ -230,4 +230,20 @@ app: # The timeout for a metrics scrape. scrapeTimeout: 5s # Additional labels to add to the ServiceMonitor. - labels: {} \ No newline at end of file + labels: {} + # Note that you can not enable both PodMonitor and ServiceMonitor as they are mutually exclusive. Enabling both will result in a error. + podmonitor: + # The PodMonitor resource for this Service. + enabled: false + # Specifies the `prometheus` label on the created PodMonitor. This is + # used when different Prometheus instances have label selectors matching + # different PodMonitors. + prometheusInstance: default + # The interval to scrape metrics. + interval: 10s + # The timeout before a metrics scrape fails. + scrapeTimeout: 5s + # Additional labels to add to the PodMonitor. + labels: {} + # Additional annotations to add to the PodMonitor. + annotations: {}