apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ include "zabbix-agent.fullname" . }}
  labels:
    {{- include "zabbix-agent.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      {{- include "zabbix-agent.selectorLabels" . | nindent 6 }}
  template:
    metadata:
    {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      labels:
        {{- include "zabbix-agent.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      hostPID: true
      hostIPC: true
      hostNetwork: true
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
          - containerPort: 10050
          env:
            - name: ZBX_DEBUGLEVEL
              value: "{{ .Values.zabbix.debugLevel }}"
            - name: ZBX_ENABLEREMOTECOMMANDS
              value: "{{ .Values.zabbix.enableRemoteCommands }}"
            - name: ZBX_METADATAITEM
              value: "{{ .Values.zabbix.metadataItem }}"
            - name: ZBX_HOSTNAMEITEM
              value: "{{ .Values.zabbix.hostnameItem }}"
            - name: ZBX_REFRESHACTIVECHECKS
              value: "{{ .Values.zabbix.refreshActiveChecks }}"
            - name: ZBX_SERVER_HOST
              value: "{{ .Values.zabbix.serverHost }}"
            - name: ZBX_STARTAGENTS
              value: "{{ .Values.zabbix.startAgents }}"
            - name: ZBX_TIMEOUT
              value: "{{ .Values.zabbix.timeout }}"
          volumeMounts:
            - name: proc
              mountPath: /data/proc
            - name: sys
              mountPath: /sys
            - name: dev
              mountPath: /data/dev
            - name: dockersock
              mountPath: /var/run/docker.sock
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
        - name: proc
          hostPath:
              path: /proc
        - name: sys
          hostPath:
              path: /sys
        - name: dev
          hostPath:
              path: /dev
        - name: dockersock
          hostPath:
              path: /var/run/docker.sock