From 85c815e9a9e539d2644a0ac3c36f03b34a77cac1 Mon Sep 17 00:00:00 2001 From: Marius Kimmina Date: Thu, 24 Oct 2024 08:56:48 +0200 Subject: [PATCH] [prometheus-node-exporter] prevent node exporter from being scheduled on fargate or virtual nodes Signed-off-by: Marius Kimmina --- charts/prometheus-node-exporter/Chart.yaml | 2 +- .../templates/_helpers.tpl | 35 +++++++++++++++++++ .../templates/daemonset.yaml | 4 +-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/charts/prometheus-node-exporter/Chart.yaml b/charts/prometheus-node-exporter/Chart.yaml index 2393e86f27a1..e52d29ee5631 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.40.0 +version: 4.40.1 appVersion: 1.8.2 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 6f6518b71977..890c487a8f50 100644 --- a/charts/prometheus-node-exporter/templates/_helpers.tpl +++ b/charts/prometheus-node-exporter/templates/_helpers.tpl @@ -200,3 +200,38 @@ labelValueLengthLimit: {{ . }} {{- end }} {{- end }} {{- end }} + +{{/* +The default node affinity to exclude +- AWS Fargate +- Azure virtual nodes +*/}} +{{- define "prometheus-node-exporter.defaultAffinity" -}} +nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: eks.amazonaws.com/compute-type + operator: NotIn + values: + - fargate + - key: type + operator: NotIn + values: + - virtual-kubelet +{{- end -}} +{{- define "prometheus-node-exporter.mergedAffinities" -}} +{{- $defaultAffinity := include "prometheus-node-exporter.defaultAffinity" . | fromYaml -}} +{{- with .Values.affinity -}} + {{- if .nodeAffinity -}} + {{- $_ := set $defaultAffinity "nodeAffinity" (mergeOverwrite $defaultAffinity.nodeAffinity .nodeAffinity) -}} + {{- end -}} + {{- if .podAffinity -}} + {{- $_ := set $defaultAffinity "podAffinity" .podAffinity -}} + {{- end -}} + {{- if .podAntiAffinity -}} + {{- $_ := set $defaultAffinity "podAntiAffinity" .podAntiAffinity -}} + {{- end -}} +{{- end -}} +{{- toYaml $defaultAffinity -}} +{{- end -}} diff --git a/charts/prometheus-node-exporter/templates/daemonset.yaml b/charts/prometheus-node-exporter/templates/daemonset.yaml index 37ac60e675b7..e5430b3e91b5 100644 --- a/charts/prometheus-node-exporter/templates/daemonset.yaml +++ b/charts/prometheus-node-exporter/templates/daemonset.yaml @@ -249,10 +249,8 @@ spec: hostNetwork: {{ .Values.hostNetwork }} hostPID: {{ .Values.hostPID }} hostIPC: {{ .Values.hostIPC }} - {{- with .Values.affinity }} affinity: - {{- toYaml . | nindent 8 }} - {{- end }} + {{- include "prometheus-node-exporter.mergedAffinities" . | nindent 8 }} {{- with .Values.dnsConfig }} dnsConfig: {{- toYaml . | nindent 8 }}