apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ include "aws-efa-k8s-device-plugin.fullname" . }}
  labels:
    {{- include "aws-efa-k8s-device-plugin.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      name:  {{ include "aws-efa-k8s-device-plugin.fullname" . }}
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      {{- if .Values.additionalPodAnnotations }}
      annotations:
        {{- with .Values.additionalPodAnnotations }}
          {{- toYaml . | nindent 8 }}
        {{- end }}
        {{- end }}
      labels:
        name: {{ include "aws-efa-k8s-device-plugin.fullname" . }}
        {{- with .Values.additionalPodLabels }}
          {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      tolerations:
        - key: CriticalAddonsOnly
          operator: Exists
        {{- with .Values.tolerations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
      # Mark this pod as a critical add-on; when enabled, the critical add-on
      # scheduler reserves resources for critical add-on pods so that they can
      # be rescheduled after a failure.
      # See https://kubernetes.io/docs/tasks/administer-cluster/guaranteed-scheduling-critical-addon-pods/
      priorityClassName: "system-node-critical"
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              {{- range .Values.supportedInstanceLabels.keys }}
              - matchExpressions:
                - key: {{ . }}
                  operator: In
                  values:
                    {{- toYaml $.Values.supportedInstanceLabels.values | nindent 20 }}
              {{- end }}
                - key: eks.amazonaws.com/compute-type
                  operator: NotIn
                  values:
                  - auto
      hostNetwork: true
      containers:
        - image: {{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}
          name: aws-efa-k8s-device-plugin
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12}}
          {{- with .Values.resources }}
          resources:
            {{- toYaml . | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: device-plugin
              mountPath: /var/lib/kubelet/device-plugins
            - name: infiniband-volume
              mountPath: /dev/infiniband/
      volumes:
        - name: device-plugin
          hostPath:
            path: /var/lib/kubelet/device-plugins
        - name: infiniband-volume
          hostPath:
            path: /dev/infiniband/