{{- if .Values.sysdig.accessKey }}
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: {{ template "sysdig.fullname" . }}
  labels:
    app: {{ template "sysdig.fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    release: "{{ .Release.Name }}"
    heritage: "{{ .Release.Service }}"
spec:
  template:
    metadata:
      name: {{ template "sysdig.fullname" .}}
      labels:
        app: {{ template "sysdig.fullname" .}}
        role: monitoring
    spec:
      serviceAccountName: {{ template "sysdig.serviceAccountName" .}}
      tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      hostPID: true
      terminationGracePeriodSeconds: 5
      {{- if .Values.image.pullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.image.pullSecrets | indent 8 }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: {{ template "sysdig.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          resources:
{{ toYaml .Values.resources | indent 12 }}
          securityContext:
            privileged: true
          readinessProbe:
            exec:
              command: [ "test", "-e", "/opt/draios/logs/running" ]
            initialDelaySeconds: 10
          volumeMounts:
            - mountPath: /host/dev
              name: dev-vol
              readOnly: false
            - mountPath: /host/proc
              name: proc-vol
              readOnly: true
            - mountPath: /host/boot
              name: boot-vol
              readOnly: true
            - mountPath: /host/lib/modules
              name: modules-vol
              readOnly: true
            - mountPath: /host/usr
              name: usr-vol
              readOnly: true
            - mountPath: /host/run
              name: run-vol
            - mountPath: /host/var/run
              name: varrun-vol
            - mountPath: /dev/shm
              name: dshm
            - mountPath: /opt/draios/etc/kubernetes/config
              name: sysdig-agent-config
            - mountPath: /opt/draios/etc/kubernetes/secrets
              name: sysdig-agent-secrets
            {{- if .Values.customAppChecks }}
            - mountPath: /opt/draios/lib/python/checks.custom.d
              name: custom-app-checks-volume
            {{- end }}
      volumes:
        - name: dshm
          emptyDir:
            medium: Memory
        - name: dev-vol
          hostPath:
            path: /dev
        - name: proc-vol
          hostPath:
            path: /proc
        - name: boot-vol
          hostPath:
            path: /boot
        - name: modules-vol
          hostPath:
            path: /lib/modules
        - name: usr-vol
          hostPath:
            path: /usr
        - name: run-vol
          hostPath:
            path: /run
        - name: varrun-vol
          hostPath:
            path: /var/run
        - name: sysdig-agent-config
          configMap:
            name: {{ template "sysdig.fullname" . }}
            optional: true
        - name: sysdig-agent-secrets
          secret:
            secretName: {{ template "sysdig.fullname" . }}
        {{- if .Values.customAppChecks }}
        - name: custom-app-checks-volume
          configMap:
            name: {{ template "sysdig.fullname" . }}-custom-app-checks
        {{- end }}
  updateStrategy:
{{ toYaml .Values.daemonset.updateStrategy | indent 4 }}
{{- end }}
