{{- if .Values.custom.discovery.enabled }}
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ printf "%s-daemonset" .Values.custom.discovery.name }}
  {{- if .Values.custom.discovery.discoveryHandlerName }}
  annotations:
    akri.sh/discoveryHandlerName: {{ .Values.custom.discovery.discoveryHandlerName }}
  {{- end }}
  labels: {{- include "akri.labels" . | nindent 4 }}
    app.kubernetes.io/name: {{ .Values.custom.discovery.name }}
    app.kubernetes.io/component: discovery-handler
spec:
  selector:
    matchLabels: {{- include "akri.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/name: {{ .Values.custom.discovery.name }}
  template:
    metadata:
      labels: {{- include "akri.labels" . | nindent 8 }}
        app.kubernetes.io/name: {{ .Values.custom.discovery.name }}
        app.kubernetes.io/component: discovery-handler
    spec:
      containers:
      - name: {{ .Values.custom.discovery.name }}
        image: {{ printf "%s:%s" (required "A custom.discovery.image.repository is required." .Values.custom.discovery.image.repository) .Values.custom.discovery.image.tag | quote }}
        {{- with .Values.custom.discovery.image.pullPolicy }}
        imagePullPolicy: {{ . }}
        {{- end}}
        resources:
          requests:
            memory: {{ .Values.custom.discovery.resources.memoryRequest }}
            cpu: {{ .Values.custom.discovery.resources.cpuRequest }}
          limits:
            memory: {{ .Values.custom.discovery.resources.memoryLimit }}
            cpu: {{ .Values.custom.discovery.resources.cpuLimit }}
        {{- if .Values.custom.discovery.useNetworkConnection }}
        ports:
        - name: discovery
          containerPort: {{ .Values.custom.discovery.port }}
        {{- end }}
        env:
        {{- if .Values.custom.discovery.useNetworkConnection }}
        - name: POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        {{- end }}
        - name: DISCOVERY_HANDLERS_DIRECTORY
          value: /var/lib/akri
        volumeMounts:
        - name: discovery-handlers
          mountPath: /var/lib/akri
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      nodeSelector:
        "kubernetes.io/os": linux
        {{- if .Values.custom.discovery.nodeSelectors }}
          {{- toYaml .Values.custom.discovery.nodeSelectors | nindent 8 }}
        {{- end }}
      volumes:
      - name: discovery-handlers
        hostPath:
          path: {{ .Values.agent.host.discoveryHandlers }}
{{- end }}