Skip to content

Commit

Permalink
use templates to merge default and user provided affinity
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuskimmina committed Jul 24, 2024
1 parent 092e199 commit 2c75a3b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
24 changes: 24 additions & 0 deletions charts/prometheus-node-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,27 @@ labelValueLengthLimit: {{ . }}
{{- end }}
{{- end }}
{{- end }}

{{/*
The default node affinity to exclude Fargate nodes and merge with user-defined affinity
*/}}
{{- define "prometheus-node-exporter.defaultAffinity" -}}
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: eks.amazonaws.com/compute-type
operator: NotIn
values:
- fargate
{{- end -}}

{{- define "prometheus-node-exporter.mergeAffinities" -}}
{{- $defaultAffinity := include "prometheus-node-exporter.defaultAffinity" . | fromYaml -}}
{{- $userAffinity := .Values.affinity -}}
{{- if and $userAffinity $userAffinity.nodeAffinity -}}
{{- $mergedNodeAffinity := merge $defaultAffinity.nodeAffinity $userAffinity.nodeAffinity -}}
{{- $_ := set $defaultAffinity "nodeAffinity" $mergedNodeAffinity -}}
{{- end -}}
{{- toYaml $defaultAffinity -}}
{{- end -}}
12 changes: 1 addition & 11 deletions charts/prometheus-node-exporter/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,7 @@ spec:
hostNetwork: {{ .Values.hostNetwork }}
hostPID: {{ .Values.hostPID }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: eks.amazonaws.com/compute-type
operator: NotIn
values:
- fargate
{{- with .Values.affinity }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "prometheus-node-exporter.mergeAffinities" . | nindent 8 }}
{{- with .Values.dnsConfig }}
dnsConfig:
{{- toYaml . | nindent 8 }}
Expand Down

0 comments on commit 2c75a3b

Please sign in to comment.