---
apiVersion: apps/v1
kind: Deployment
metadata:
  name:  {{ template "aws-eks-asg-rolling-update-handler.name" . }}
  namespace: {{ template "aws-eks-asg-rolling-update-handler.namespace" . }}
  labels:
{{ include "aws-eks-asg-rolling-update-handler.labels" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
{{ include "aws-eks-asg-rolling-update-handler.labels" . | indent 6 }}
  template:
    metadata:
      labels:
{{ include "aws-eks-asg-rolling-update-handler.labels" . | indent 8 }}
      {{- with .Values.podLabels }}
      {{- toYaml . | nindent 8 }}
      {{- end }}
      annotations:
      {{- with .Values.podAnnotations }}
      {{- toYaml . | nindent 8 }}
      {{- end }}
    spec:
      {{- if .Values.securityContext }}
      securityContext:
        {{ toYaml .Values.securityContext | nindent 8 | trim }}
      {{- end }}
      automountServiceAccountToken: true
      serviceAccountName: {{ template "aws-eks-asg-rolling-update-handler.serviceAccountName" . }}
      restartPolicy: Always
      dnsPolicy: Default
      containers:
        - name: {{ template "aws-eks-asg-rolling-update-handler.name" . }}
          image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          {{- if .Values.containerSecurityContext }}
          securityContext:
            {{ toYaml .Values.containerSecurityContext | nindent 12 | trim }}
          {{- end }}
          env:
{{- toYaml .Values.environmentVars | nindent 12 }}
{{- with .Values.resources }}
          resources:
{{- toYaml . | nindent 12 }}
{{- end }}
          volumeMounts:
            - name: aws-token
              mountPath: "/var/run/secrets/sts.amazonaws.com/serviceaccount/"
              readOnly: true
      volumes:
        - name: aws-token
          projected:
            sources:
            - serviceAccountToken:
                path: token
                expirationSeconds: 86400
                audience: "sts.amazonaws.com"
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
