apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ template "magic-ip-address.fullname" . }}
  labels:
    app: {{ template "magic-ip-address.name" . }}
    chart: {{ template "magic-ip-address.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  selector:
    matchLabels:
      app: {{ template "magic-ip-address.name" . }}
      release: {{ .Release.Name }}
  minReadySeconds: 10
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
  template:
    metadata:
      labels:
        app: {{ template "magic-ip-address.name" . }}
        release: {{ .Release.Name }}
      annotations:
        checksum/secret: {{ toYaml .Values.config | sha256sum }}
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        envFrom:
        - secretRef:
            name: {{ template "magic-ip-address.fullname" . }}
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        securityContext:
          runAsUser: 0
        resources:
{{ toYaml .Values.resources | indent 10 }}
      terminationGracePeriodSeconds: 60
      serviceAccountName: {{ template "magic-ip-address.serviceAccountName" . }}
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
{{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
{{- end }}
