apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ include "caretta.name" . }}
  labels:
    app: caretta
    {{- include "caretta.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      app: caretta
      {{- include "caretta.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
    {{- with .Values.podAnnotations }}
        {{- toYaml . | nindent 8 }}
    {{- end }}
      labels:
        app: caretta
        {{- include "caretta.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "caretta.name" . }}
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName }}
      {{- end }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          volumeMounts:
            - mountPath: /proc
              name: proc
            - mountPath: /sys/kernel/debug
              name: debug
          ports:
            - name: prom-metrics
              containerPort: {{ .Values.prometheusPort }}
              protocol: TCP
          env:
            - name: "RESOLVE_DNS"
              value: "{{ .Values.enableDnsResolving }}"
            - name: "PROMETHEUS_PORT"
              value: "{{ .Values.prometheusPort }}"
            - name: "PROMETHEUS_ENDPOINT"
              value: "{{ .Values.prometheusEndpoint }}"
            - name: "POLL_INTERVAL"
              value: "{{ .Values.pollIntervalSeconds }}"
          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: debug
          hostPath:
            path: /sys/kernel/debug