Skip to content

Commit d402543

Browse files
committed
[prometheus-node-exporter] Add optional initContainers for permission fixes
Signed-off-by: henrichter <hr.richterhenry@gmail.com>
1 parent 59dc936 commit d402543

File tree

3 files changed

+60
-14
lines changed

3 files changed

+60
-14
lines changed

charts/prometheus-node-exporter/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords:
66
- prometheus
77
- exporter
88
type: application
9-
version: 4.51.1
9+
version: 4.52.0
1010
# renovate: github=prometheus/node_exporter
1111
appVersion: 1.10.2
1212
home: https://github.com/prometheus/node_exporter/

charts/prometheus-node-exporter/templates/daemonset.yaml

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,55 @@ spec:
3838
{{- with .Values.priorityClassName }}
3939
priorityClassName: {{ . }}
4040
{{- end }}
41+
{{- $fixes := .Values.permissionInitContainers.fixes -}}
42+
{{- $fixesEnabled := or $fixes.rapl $fixes.slabinfo (not (empty .Values.permissionInitContainers.extraCommands)) -}}
43+
{{- if or .Values.extraInitContainers $fixesEnabled }}
4144
initContainers:
42-
{{- if .Values.extraInitContainers }}
43-
{{- toYaml .Values.extraInitContainers | nindent 8 }}
44-
{{- end }}
45-
- name: chown-powercap
46-
image: busybox:latest
47-
command: ["/bin/sh", "-c"]
48-
args:
45+
{{- if .Values.extraInitContainers }}
46+
{{- toYaml .Values.extraInitContainers | nindent 8 }}
47+
{{- end }}
48+
{{- if $fixesEnabled }}
49+
- name: permission-fix
50+
{{- if .Values.permissionInitContainers.image.sha }}
51+
image: "{{ .Values.global.imageRegistry | default .Values.permissionInitContainers.image.registry}}/{{ .Values.permissionInitContainers.image.repository }}:{{ .Values.permissionInitContainers.image.tag }}@sha256:{{ .Values.permissionInitContainers.image.sha }}"
52+
{{- else }}
53+
image: "{{ .Values.global.imageRegistry | default .Values.permissionInitContainers.image.registry}}/{{ .Values.permissionInitContainers.image.repository }}:{{ .Values.permissionInitContainers.image.tag }}"
54+
{{- end }}
55+
imagePullPolicy: {{ .Values.permissionInitContainers.image.pullPolicy }}
56+
securityContext:
57+
{{- toYaml .Values.permissionInitContainers.securityContext | nindent 12 }}
58+
command:
59+
- /bin/sh
60+
- -c
4961
- |
50-
if [ -d /host/sys/devices/virtual/powercap ]; then
51-
find /host/sys/devices/virtual/powercap -name energy_uj -exec chown root:{{ .Values.securityContext.runAsGroup }} {} + -exec chmod g+r -R {} +;
62+
{{- if $fixes.rapl }}
63+
powercap_path="/host/sys/devices/virtual/powercap"
64+
if [ -d "$powercap_path" ]; then
65+
find "$powercap_path" -name energy_uj -exec chown root:{{ .Values.securityContext.runAsGroup }} {} + -exec chmod g+r -R {} +
5266
fi
53-
securityContext:
54-
runAsUser: 0
55-
runAsNonRoot: false
56-
privileged: true
67+
{{- end }}
68+
{{- if $fixes.slabinfo }}
69+
slabinfo_path="/host/proc/slabinfo"
70+
if [ -f "$slabinfo_path" ]; then
71+
chown root:{{ .Values.securityContext.runAsGroup }} "$slabinfo_path" && chmod g+r "$slabinfo_path"
72+
fi
73+
{{- end }}
74+
{{- range .Values.permissionInitContainers.extraCommands }}
75+
{{ . }}
76+
{{- end }}
5777
volumeMounts:
78+
{{- if $fixes.rapl }}
5879
- name: sys
5980
mountPath: /host/sys
6081
readOnly: false
82+
{{- end }}
83+
{{- if $fixes.slabinfo }}
84+
- name: proc
85+
mountPath: /host/proc
86+
readOnly: false
87+
{{- end }}
88+
{{- end }}
89+
{{- end }}
6190
serviceAccountName: {{ include "prometheus-node-exporter.serviceAccountName" . }}
6291
{{- with .Values.terminationGracePeriodSeconds }}
6392
terminationGracePeriodSeconds: {{ . }}

charts/prometheus-node-exporter/values.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,23 @@ sidecarHostVolumeMounts: []
543543
##
544544
extraInitContainers: []
545545

546+
permissionInitContainers:
547+
image:
548+
registry: quay.io
549+
repository: prometheus/busybox
550+
tag: latest
551+
sha: ""
552+
pullPolicy: IfNotPresent
553+
securityContext:
554+
privileged: true
555+
runAsUser: 0
556+
runAsGroup: 0
557+
runAsNonRoot: false
558+
fixes:
559+
rapl: false
560+
slabinfo: false
561+
extraCommands: []
562+
546563
## Liveness probe
547564
##
548565
livenessProbe:

0 commit comments

Comments
 (0)