apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ include "aws-cloudwatch-metrics.fullname" . }}
  labels:
    {{- include "aws-cloudwatch-metrics.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      {{- include "aws-cloudwatch-metrics.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "aws-cloudwatch-metrics.selectorLabels" . | nindent 8 }}
    spec:
      serviceAccountName: {{ include "aws-cloudwatch-metrics.serviceAccountName" . }}
      hostNetwork: {{ .Values.hostNetwork }}
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        {{- include "aws-cloudwatch-metrics.statsdConfig" . | nindent 8 -}}
        # Please don't change below envs
        env:
        - name: HOST_IP
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
        - name: HOST_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: K8S_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: CI_VERSION
          value: "k8s/1.3.9"
        # Please don't change the mountPath
        volumeMounts:
        - name: cwagentconfig
          mountPath: /etc/cwagentconfig
        - name: rootfs
          mountPath: /rootfs
          readOnly: true
        - name: dockersock
          mountPath: /var/run/docker.sock
          readOnly: true
        - name: varlibdocker
          mountPath: /var/lib/docker
          readOnly: true
        - name: containerdsock
          mountPath: /run/containerd/containerd.sock
          readOnly: true
        - name: sys
          mountPath: /sys
          readOnly: true
        - name: devdisk
          mountPath: /dev/disk
          readOnly: true
        resources:
          {{- toYaml .Values.resources | nindent 10 }}
      volumes:
      - name: cwagentconfig
        configMap:
          name: {{ include "aws-cloudwatch-metrics.fullname" . }}
      - name: rootfs
        hostPath:
          path: /
      - name: dockersock
        hostPath:
          path: /var/run/docker.sock
      - name: varlibdocker
        hostPath:
          path: /var/lib/docker
      - name: containerdsock
        hostPath:
          path: {{ .Values.containerdSockPath }}
      - name: sys
        hostPath:
          path: /sys
      - name: devdisk
        hostPath:
          path: /dev/disk/
      terminationGracePeriodSeconds: 60
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName }}
      {{- end }}
