apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: {{ template "k8s-spot-termination-handler.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ template "k8s-spot-termination-handler.name" . }}
    helm.sh/chart: {{ template "k8s-spot-termination-handler.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ template "k8s-spot-termination-handler.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ template "k8s-spot-termination-handler.serviceAccountName" . }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
            {{- if not .Values.enableLogspout }}
            - name: LOGSPOUT
              value: "ignore"
            {{- end }}
            {{- with .Values.slackUrl }}
            - name: SLACK_URL
              value: {{ . | quote }}
            {{- end }}
            {{- with .Values.detachAsg }}
            - name: DETACH_ASG
              value: {{ . | quote }}
            {{- end }}
            - name: POLL_INTERVAL
              value: {{ .Values.pollInterval | quote }}
            - name: CLUSTER
              value: {{ .Values.clusterName | quote }}
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
