From 670d2c3a5a4fe7b52fa0921a61b42666e7c6801c Mon Sep 17 00:00:00 2001 From: zeritti <47476160+zeritti@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:16:28 +0000 Subject: [PATCH] [prometheus] Support retention size, attach volume labels to PVC (#3985) * Remove unused helper template prometheus.daemonset.apiVersion Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> * Attach labels to standalone PVC Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> * Minor corrections in comments Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> * Do not render resources unless set Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> * Update values schema Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> * Add support for data retention size Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> * Bump chart version Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> * Insert commonMetaLabels in values file Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> * Add header to values file Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> * Bump chart version Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> --------- Signed-off-by: zeritti <47476160+zeritti@users.noreply.github.com> Co-authored-by: MH --- charts/prometheus/Chart.yaml | 2 +- charts/prometheus/templates/_helpers.tpl | 10 ++++------ charts/prometheus/templates/deploy.yaml | 11 +++++++++-- charts/prometheus/templates/pvc.yaml | 3 +++ charts/prometheus/templates/sts.yaml | 11 +++++++++-- charts/prometheus/values.schema.json | 9 +++++++++ charts/prometheus/values.yaml | 21 +++++++++++++++++---- 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/charts/prometheus/Chart.yaml b/charts/prometheus/Chart.yaml index af43851ebac..9895486b48b 100644 --- a/charts/prometheus/Chart.yaml +++ b/charts/prometheus/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: prometheus appVersion: v2.47.2 -version: 25.5.0 +version: 25.6.0 kubeVersion: ">=1.19.0-0" description: Prometheus is a monitoring system and time series database. home: https://prometheus.io/ diff --git a/charts/prometheus/templates/_helpers.tpl b/charts/prometheus/templates/_helpers.tpl index daec18e2805..0810e3c0444 100644 --- a/charts/prometheus/templates/_helpers.tpl +++ b/charts/prometheus/templates/_helpers.tpl @@ -110,12 +110,7 @@ Return the appropriate apiVersion for deployment. {{- define "prometheus.deployment.apiVersion" -}} {{- print "apps/v1" -}} {{- end -}} -{{/* -Return the appropriate apiVersion for daemonset. -*/}} -{{- define "prometheus.daemonset.apiVersion" -}} -{{- print "apps/v1" -}} -{{- end -}} + {{/* Return the appropriate apiVersion for networkpolicy. */}} @@ -133,6 +128,7 @@ Return the appropriate apiVersion for poddisruptionbudget. {{- print "policy/v1beta1" -}} {{- end -}} {{- end -}} + {{/* Return the appropriate apiVersion for rbac. */}} @@ -143,6 +139,7 @@ Return the appropriate apiVersion for rbac. {{- print "rbac.authorization.k8s.io/v1beta1" -}} {{- end -}} {{- end -}} + {{/* Return the appropriate apiVersion for ingress. */}} @@ -169,6 +166,7 @@ Return if ingress supports ingressClassName. {{- define "ingress.supportsIngressClassName" -}} {{- or (eq (include "ingress.isStable" .) "true") (and (eq (include "ingress.apiVersion" .) "networking.k8s.io/v1beta1") (semverCompare ">= 1.18.x" (include "prometheus.kubeVersion" .))) -}} {{- end -}} + {{/* Return if ingress supports pathType. */}} diff --git a/charts/prometheus/templates/deploy.yaml b/charts/prometheus/templates/deploy.yaml index cf243ea0523..9ccdccfe4fe 100644 --- a/charts/prometheus/templates/deploy.yaml +++ b/charts/prometheus/templates/deploy.yaml @@ -85,8 +85,10 @@ spec: ports: - containerPort: {{ .Values.configmapReload.prometheus.containerPort }} {{- end }} + {{- with .Values.configmapReload.prometheus.resources }} resources: -{{ toYaml .Values.configmapReload.prometheus.resources | indent 12 }} + {{- toYaml . | nindent 12 }} + {{- end }} volumeMounts: - name: config-volume mountPath: /etc/config @@ -123,6 +125,9 @@ spec: {{- else }} {{- if .Values.server.retention }} - --storage.tsdb.retention.time={{ .Values.server.retention }} + {{- end }} + {{- if .Values.server.retentionSize }} + - --storage.tsdb.retention.size={{ .Values.server.retentionSize }} {{- end }} - --config.file={{ .Values.server.configPath }} {{- if .Values.server.storagePath }} @@ -213,8 +218,10 @@ spec: periodSeconds: {{ .Values.server.startupProbe.periodSeconds }} timeoutSeconds: {{ .Values.server.startupProbe.timeoutSeconds }} {{- end }} + {{- with .Values.server.resources }} resources: -{{ toYaml .Values.server.resources | indent 12 }} + {{- toYaml . | nindent 12 }} + {{- end }} volumeMounts: - name: config-volume mountPath: /etc/config diff --git a/charts/prometheus/templates/pvc.yaml b/charts/prometheus/templates/pvc.yaml index 25dfe0217ca..a9dc4fce083 100644 --- a/charts/prometheus/templates/pvc.yaml +++ b/charts/prometheus/templates/pvc.yaml @@ -10,6 +10,9 @@ metadata: {{- end }} labels: {{- include "prometheus.server.labels" . | nindent 4 }} + {{- with .Values.server.persistentVolume.labels }} + {{- toYaml . | nindent 4 }} + {{- end }} name: {{ template "prometheus.server.fullname" . }} namespace: {{ include "prometheus.namespace" . }} spec: diff --git a/charts/prometheus/templates/sts.yaml b/charts/prometheus/templates/sts.yaml index 811190da322..e0693b865e1 100644 --- a/charts/prometheus/templates/sts.yaml +++ b/charts/prometheus/templates/sts.yaml @@ -90,8 +90,10 @@ spec: ports: - containerPort: {{ .Values.configmapReload.prometheus.containerPort }} {{- end }} + {{- with .Values.configmapReload.prometheus.resources }} resources: -{{ toYaml .Values.configmapReload.prometheus.resources | indent 12 }} + {{- toYaml . | nindent 12 }} + {{- end }} volumeMounts: - name: config-volume mountPath: /etc/config @@ -128,6 +130,9 @@ spec: {{- end }} {{- if .Values.server.retention }} - --storage.tsdb.retention.time={{ .Values.server.retention }} + {{- end }} + {{- if .Values.server.retentionSize }} + - --storage.tsdb.retention.size={{ .Values.server.retentionSize }} {{- end }} - --config.file={{ .Values.server.configPath }} {{- if .Values.server.storagePath }} @@ -215,8 +220,10 @@ spec: periodSeconds: {{ .Values.server.startupProbe.periodSeconds }} timeoutSeconds: {{ .Values.server.startupProbe.timeoutSeconds }} {{- end }} + {{- with .Values.server.resources }} resources: -{{ toYaml .Values.server.resources | indent 12 }} + {{- toYaml . | nindent 12 }} + {{- end }} volumeMounts: - name: config-volume mountPath: /etc/config diff --git a/charts/prometheus/values.schema.json b/charts/prometheus/values.schema.json index 2706c5b8405..1828064ed58 100644 --- a/charts/prometheus/values.schema.json +++ b/charts/prometheus/values.schema.json @@ -418,6 +418,9 @@ } } }, + "portName": { + "type": "string" + }, "prefixURL": { "type": "string" }, @@ -463,6 +466,9 @@ "retention": { "type": "string" }, + "retentionSize": { + "type": "string" + }, "revisionHistoryLimit": { "type": "integer" }, @@ -486,6 +492,9 @@ "service": { "type": "object", "properties": { + "additionalPorts": { + "type": "array" + }, "annotations": { "type": "object" }, diff --git a/charts/prometheus/values.yaml b/charts/prometheus/values.yaml index bacd158a2a5..c68e8c19cf4 100644 --- a/charts/prometheus/values.yaml +++ b/charts/prometheus/values.yaml @@ -1,3 +1,8 @@ +# yaml-language-server: $schema=values.schema.json +# Default values for prometheus. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + rbac: create: true @@ -16,6 +21,9 @@ serviceAccounts: annotations: {} # automountServiceAccountToken: +## Additional labels to attach to all resources +commonMetaLabels: {} + ## Monitors ConfigMap changes and POSTs to a URL ## Ref: https://github.com/prometheus-operator/prometheus-operator/tree/main/cmd/prometheus-config-reloader ## @@ -198,6 +206,7 @@ server: # List of flags to override default parameters, e.g: # - --enable-feature=agent # - --storage.agent.retention.max-time=30m + # - --config.file=/etc/config/prometheus.yml defaultFlagsOverride: [] extraFlags: @@ -364,7 +373,7 @@ server: # - "example.com" ## Node tolerations for server scheduling to nodes with taints - ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ + ## Ref: https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/ ## tolerations: [] # - key: "key" @@ -373,7 +382,7 @@ server: # effect: "NoSchedule|PreferNoSchedule|NoExecute(1.6 only)" ## Node labels for Prometheus server pod assignment - ## Ref: https://kubernetes.io/docs/user-guide/node-selection/ + ## Ref: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/ ## nodeSelector: {} @@ -679,6 +688,10 @@ server: ## retention: "15d" + ## Prometheus' data retention size. Supported units: B, KB, MB, GB, TB, PB, EB. + ## + retentionSize: "" + ## Prometheus server ConfigMap entries for rule files (allow prometheus labels interpolation) ruleFiles: {} @@ -1206,7 +1219,7 @@ kube-state-metrics: ## enabled: true -## promtheus-node-exporter sub-chart configurable values +## prometheus-node-exporter sub-chart configurable values ## Please see https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-node-exporter ## prometheus-node-exporter: @@ -1220,7 +1233,7 @@ prometheus-node-exporter: containerSecurityContext: allowPrivilegeEscalation: false -## pprometheus-pushgateway sub-chart configurable values +## prometheus-pushgateway sub-chart configurable values ## Please see https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-pushgateway ## prometheus-pushgateway: