apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ template "node-exporter.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels: {{- include "node-exporter.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels: {{- include "node-exporter.matchLabels" . | nindent 6 }}
  updateStrategy:
{{ toYaml .Values.updateStrategy | indent 4 }}
  minReadySeconds: {{ .Values.minReadySeconds }}
  template:
    metadata:
      {{- if .Values.podAnnotations }}
      annotations: {{- include "node-exporter.tplValue" ( dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
      {{- end }}
      labels: {{- include "node-exporter.labels" . | nindent 8 }}
        {{- if .Values.podLabels }}
{{ toYaml .Values.podLabels | indent 8 }}
        {{- end }}
    spec:
      serviceAccountName: {{ template "node-exporter.serviceAccountName" . }}
{{- include "node-exporter.imagePullSecrets" . | indent 6 }}
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName }}
      {{- end }}
      {{- if .Values.securityContext.enabled }}
      securityContext:
        runAsUser: {{ .Values.securityContext.runAsUser }}
        fsGroup: {{ .Values.securityContext.fsGroup }}
        runAsNonRoot: {{ .Values.securityContext.runAsNonRoot }}
      {{- end }}
      containers:
        - name: {{ template "node-exporter.name" . }}
          image: {{ template "node-exporter.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
            - --path.procfs=/host/proc
            - --path.sysfs=/host/sys
            - --web.listen-address=0.0.0.0:{{ .Values.service.targetPort }}
            {{- range $key, $value := .Values.extraArgs }}
            {{- if $value }}
            - --{{ $key }}={{ $value }}
            {{- else }}
            - --{{ $key }}
            {{- end }}
            {{- end }}
          ports:
            - name: metrics
              containerPort: {{ .Values.service.targetPort }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: metrics
{{ toYaml .Values.livenessProbe | indent 12 }}
          readinessProbe:
            httpGet:
              path: /
              port: metrics
{{ toYaml .Values.readinessProbe | indent 12 }}
          {{- if .Values.resources }}
          resources: {{- toYaml .Values.resources | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: proc
              mountPath: /host/proc
              readOnly: true
            - name: sys
              mountPath: /host/sys
              readOnly: true
            {{- if .Values.extraVolumeMounts }}
{{ toYaml .Values.extraVolumeMounts | indent 12}}
            {{- end }}
      hostNetwork: {{ .Values.hostNetwork }}
      hostPID: true
      {{- if .Values.nodeSelector }}
      nodeSelector: {{- include "node-exporter.tplValue" (dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.tolerations }}
      tolerations: {{- include "node-exporter.tplValue" (dict "value" .Values.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.affinity }}
      affinity: {{- include "node-exporter.tplValue" (dict "value" .Values.affinity "context" $) | nindent 8 }}
      {{- end }}
      volumes:
        - name: proc
          hostPath:
            path: /proc
        - name: sys
          hostPath:
            path: /sys
        {{- if .Values.extraVolumes }}
{{ toYaml .Values.extraVolumes | indent 8 }}
        {{- end }}
