apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ .Values.application.appName }}
  labels:
    name: {{ .Values.application.appName }}
    role: agent
spec:
  selector:
    matchLabels:
      name: {{ .Values.application.appName }}
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels: 
        name: {{ .Values.application.appName }}
      annotations:
        node.kubernetes.io/bootstrap-checkpoint: "true"
    spec: 
      nodeSelector:
        {{- if .Values.nodeSelector }}
        {{- toYaml .Values.nodeSelector | nindent 8 }}
        {{- else }}
        smarter.device-manager: enabled
        {{- end }}
      tolerations:
      - key: "smarter.type"
        operator: "Equal"
        value: "edge"
        effect: "NoSchedule"
      priorityClassName: "system-node-critical"
      hostname: {{ .Values.application.appName }}
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      containers:
      - name: {{ .Values.application.appName }}
        image: {{ .Values.image.repository }}:{{ default .Chart.AppVersion .Values.image.tag }}
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop: ["ALL"]
        resources:
          limits:
            cpu: 200m
            memory: 15Mi
          requests:
            cpu: 10m
            memory: 15Mi
        volumeMounts:
          - name: device-plugin
            mountPath: /var/lib/kubelet/device-plugins
          - name: dev-dir
            mountPath: /dev
          - name: sys-dir
            mountPath: /sys
          {{- if .Values.config }}
          - name: config
            mountPath: /root/config
          {{- end }}
      volumes:
        - name: device-plugin
          hostPath:
            path: /var/lib/kubelet/device-plugins
        - name: dev-dir
          hostPath:
            path: /dev
        - name: sys-dir
          hostPath:
            path: /sys
        {{- if .Values.config }}
        - name: config
          configMap:
            name: {{ .Values.application.appName }}
        {{- end }}
      terminationGracePeriodSeconds: 30
