apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "app.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    app.kubernetes.io/name: {{ include "app.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
    k8s-app: {{ include "app.name" . }}
    helm.sh/chart: {{ include "chart.name-version" . }}
    control-plane: controller
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "app.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      annotations:
      {{- range $key, $value := .Values.deployment.annotations }}
        {{ $key }}: {{ $value | quote }}
      {{- end }}
      labels:
        app.kubernetes.io/name: {{ include "app.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/managed-by: Helm
        k8s-app: {{ include "app.name" . }}
{{- range $key, $value := .Values.deployment.labels }}
        {{ $key }}: {{ $value | quote }}
{{- end }}
    spec:
      serviceAccountName: {{ include "service-account.name" . }}
      containers:
      - command:
        - ./bin/controller
        args:
        - --aws-account-id
        - "$(AWS_ACCOUNT_ID)"
        - --aws-region
        - "$(AWS_REGION)"
        - --enable-development-logging
        - "$(ACK_ENABLE_DEVELOPMENT_LOGGING)"
        - --log-level
        - "$(ACK_LOG_LEVEL)"
        - --resource-tags
        - "$(ACK_RESOURCE_TAGS)"
        - --watch-namespace
        - "$(ACK_WATCH_NAMESPACE)"
        image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
        name: controller
        ports:
          - containerPort: {{ .Values.deployment.containerPort }}
        resources:
          {{- toYaml .Values.resources | nindent 10 }}
        env:
        - name: K8S_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: AWS_ACCOUNT_ID
          value: {{ .Values.aws.account_id | quote }}
        - name: AWS_REGION
          value: {{ .Values.aws.region }}
        - name: ACK_WATCH_NAMESPACE
          value: {{ .Values.watchNamespace }}
        - name: ACK_ENABLE_DEVELOPMENT_LOGGING
          value: {{ .Values.log.enable_development_logging | quote }}
        - name: ACK_LOG_LEVEL
          value: {{ .Values.log.level | quote }}
        - name: ACK_RESOURCE_TAGS
          value: {{ join "," .Values.resourceTags | quote }}
      terminationGracePeriodSeconds: 10
