apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ include "kubelet-volume-stats-exporter.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "kubelet-volume-stats-exporter.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      {{- include "kubelet-volume-stats-exporter.selectorLabels" . | nindent 6 }}
  {{- with .Values.daemonset.updateStrategy }}
  updateStrategy:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  template:
    metadata:
      annotations:
        {{- with .Values.daemonset.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      labels:
        {{- include "kubelet-volume-stats-exporter.selectorLabels" . | nindent 8 }}
        {{- with .Values.daemonset.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "kubelet-volume-stats-exporter.serviceAccountName" . }}
      {{- with .Values.podSecurityContext }}
      securityContext:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      hostNetwork: {{ .Values.daemonset.hostNetwork }}
      hostPID: {{ .Values.daemonset.hostPID }}
      {{- if .Values.daemonset.priorityClassName }}
      priorityClassName: {{ .Values.daemonset.priorityClassName }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: exporter
          image: {{ include "kubelet-volume-stats-exporter.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          args:
            - --kubelet-endpoint={{ .Values.config.kubeletEndpoint }}
            - --metrics-port={{ .Values.config.metricsPort }}
            - --scrape-interval={{ .Values.config.scrapeInterval }}
            - --token-path={{ .Values.config.tokenPath }}
            {{- if .Values.config.insecureSkipTLSVerify }}
            - --insecure-skip-tls-verify=true
            {{- end }}
            {{- if .Values.config.debug }}
            - --debug=true
            {{- end }}
          ports:
            - name: metrics
              containerPort: {{ .Values.config.metricsPort }}
              protocol: TCP
          {{- with .Values.livenessProbe }}
          livenessProbe:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.readinessProbe }}
          readinessProbe:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.resources }}
          resources:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          {{- with .Values.securityContext }}
          securityContext:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: token
              mountPath: /var/run/secrets/kubernetes.io/serviceaccount
              readOnly: true
      volumes:
        - name: token
          projected:
            sources:
              - serviceAccountToken:
                  path: token
                  expirationSeconds: {{ .Values.volumes.token.expirationSeconds }}
              - configMap:
                  name: kube-root-ca.crt
                  items:
                    - key: ca.crt
                      path: ca.crt
              - downwardAPI:
                  items:
                    - path: namespace
                      fieldRef:
                        fieldPath: metadata.namespace

