From 95409b9736ad4512bcaee5448d81a4e872b200c6 Mon Sep 17 00:00:00 2001 From: Thomas Decaux Date: Mon, 29 Jan 2024 11:06:12 -0500 Subject: [PATCH] [prometheus-node-exporter] Fix sidecars containers volumeMounts merge (#4177) * [node-exporter] Fix sidecars containers volumeMounts merge Signed-off-by: Thomas Decaux * bump chart version Signed-off-by: Thomas Decaux * bump chart version Signed-off-by: Thomas Decaux * Patch version Co-authored-by: MH Signed-off-by: Thomas Decaux * Update charts/prometheus-node-exporter/templates/daemonset.yaml Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> Signed-off-by: Thomas Decaux * Update charts/prometheus-node-exporter/templates/daemonset.yaml Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> Signed-off-by: Thomas Decaux * fix lint Signed-off-by: Thomas Decaux --------- Signed-off-by: Thomas Decaux Signed-off-by: Thomas Decaux Co-authored-by: MH Co-authored-by: zeritti <47476160+zeritti@users.noreply.github.com> --- charts/prometheus-node-exporter/Chart.yaml | 2 +- .../templates/_helpers.tpl | 17 +++++++++++ .../templates/daemonset.yaml | 28 +++++++------------ charts/prometheus-node-exporter/values.yaml | 15 ++++++---- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/charts/prometheus-node-exporter/Chart.yaml b/charts/prometheus-node-exporter/Chart.yaml index 83d592222528..aea1b521c30f 100644 --- a/charts/prometheus-node-exporter/Chart.yaml +++ b/charts/prometheus-node-exporter/Chart.yaml @@ -6,7 +6,7 @@ keywords: - prometheus - exporter type: application -version: 4.26.0 +version: 4.26.1 appVersion: 1.7.0 home: https://github.com/prometheus/node_exporter/ sources: diff --git a/charts/prometheus-node-exporter/templates/_helpers.tpl b/charts/prometheus-node-exporter/templates/_helpers.tpl index 84552fe475a9..8e84832cbf7f 100644 --- a/charts/prometheus-node-exporter/templates/_helpers.tpl +++ b/charts/prometheus-node-exporter/templates/_helpers.tpl @@ -183,3 +183,20 @@ labelNameLengthLimit: {{ . }} labelValueLengthLimit: {{ . }} {{- end }} {{- end }} + +{{/* Sets sidecar volumeMounts */}} +{{- define "prometheus-node-exporter.sidecarVolumeMounts" -}} +{{- range $_, $mount := $.Values.sidecarVolumeMount }} +- name: {{ $mount.name }} + mountPath: {{ $mount.mountPath }} + readOnly: {{ $mount.readOnly }} +{{- end }} +{{- range $_, $mount := $.Values.sidecarHostVolumeMounts }} +- name: {{ $mount.name }} + mountPath: {{ $mount.mountPath }} + readOnly: {{ $mount.readOnly }} +{{- if $mount.mountPropagation }} + mountPropagation: {{ $mount.mountPropagation }} +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/prometheus-node-exporter/templates/daemonset.yaml b/charts/prometheus-node-exporter/templates/daemonset.yaml index 82dba5cabeec..bcba856f916e 100644 --- a/charts/prometheus-node-exporter/templates/daemonset.yaml +++ b/charts/prometheus-node-exporter/templates/daemonset.yaml @@ -160,24 +160,16 @@ spec: - name: {{ .name }} mountPath: {{ .mountPath }} {{- end }} - {{- with .Values.sidecars }} - {{- toYaml . | nindent 8 }} - {{- if or $.Values.sidecarVolumeMount $.Values.sidecarHostVolumeMounts }} - volumeMounts: - {{- range $_, $mount := $.Values.sidecarVolumeMount }} - - name: {{ $mount.name }} - mountPath: {{ $mount.mountPath }} - readOnly: {{ $mount.readOnly }} - {{- end }} - {{- range $_, $mount := $.Values.sidecarHostVolumeMounts }} - - name: {{ $mount.name }} - mountPath: {{ $mount.mountPath }} - readOnly: {{ $mount.readOnly }} - {{- if $mount.mountPropagation }} - mountPropagation: {{ $mount.mountPropagation }} - {{- end }} - {{- end }} - {{- end }} + {{- range .Values.sidecars }} + {{- $overwrites := dict + "volumeMounts" (concat (include "prometheus-node-exporter.sidecarVolumeMounts" $ | fromYamlArray) (.volumeMounts | default list) | default list) + }} + {{- $defaults := dict + "image" (include "prometheus-node-exporter.image" $) + "securityContext" $.Values.containerSecurityContext + "imagePullPolicy" $.Values.image.pullPolicy + }} + - {{- toYaml (merge $overwrites . $defaults) | nindent 10 }} {{- end }} {{- if .Values.kubeRBACProxy.enabled }} - name: kube-rbac-proxy diff --git a/charts/prometheus-node-exporter/values.yaml b/charts/prometheus-node-exporter/values.yaml index fad11ea0e27f..8f3a038307f1 100644 --- a/charts/prometheus-node-exporter/values.yaml +++ b/charts/prometheus-node-exporter/values.yaml @@ -395,18 +395,21 @@ secrets: [] ## namespaceOverride: "" -## Additional containers for export metrics to text file +## Additional containers for export metrics to text file; fields image,imagePullPolicy,securityContext take default value from main container ## sidecars: [] -## - name: nvidia-dcgm-exporter -## image: nvidia/dcgm-exporter:1.4.3 +# - name: nvidia-dcgm-exporter +# image: nvidia/dcgm-exporter:1.4.3 +# volumeMounts: +# - name: tmp +# mountPath: /tmp ## Volume for sidecar containers ## sidecarVolumeMount: [] -## - name: collector-textfiles -## mountPath: /run/prometheus -## readOnly: false +# - name: collector-textfiles +# mountPath: /run/prometheus +# readOnly: false ## Additional mounts from the host to sidecar containers ##