apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ include "keepalived.fullname" . }}
  labels:
    {{- include "keepalived.labels" . | nindent 4 }}
spec:
  selector:
    matchLabels:
      {{- include "keepalived.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "keepalived.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      hostNetwork: true
      containers:
        - name: {{ .Chart.Name }}
          env:
          - name: AUTH_PASS
            value: "{{ .Values.keepalived.auth_pass }}"
          - name: CHECK_PORT
            value: "{{ .Values.keepalived.check_port }}"
          - name: CHECK_SCRIPT
            value: "{{ .Values.keepalived.check_script }}"
          - name: INTERFACE
            value: "{{ .Values.keepalived.interface }}"
          - name: VIRTUAL_IP
            value: "{{ .Values.keepalived.virtual_ip }}"
          - name: VIRTUAL_MASK
            value: "{{ .Values.keepalived.virtual_mask }}"
          - name: VRID
            value: "{{ .Values.keepalived.vrid }}"
          image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          securityContext:
            capabilities:
              add:
              - NET_ADMIN
              - NET_BROADCAST
          stdin: true
          tty: true
          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 }}
      restartPolicy: Always