apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: {{ template "name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  name: {{ template "fullname" . }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
    {{- if .Values.podAnnotations }}
      annotations:
{{ toYaml .Values.podAnnotations | indent 8 }}
    {{- end }}
      labels:
        app: {{ template "name" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ template "name" . }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: "{{ .Values.image.pullPolicy }}"
          command:
            - ./cluster-autoscaler
            - --cloud-provider=aws
          {{- range .Values.autoscalingGroups }}
            - --nodes={{ .minSize }}:{{ .maxSize }}:{{ .name }}
          {{- end }}
            - --scale-down-delay={{ .Values.scaleDownDelay }}
            - --skip-nodes-with-local-storage={{ .Values.skipNodes.withLocalStorage }}
            - --skip-nodes-with-system-pods={{ .Values.skipNodes.withSystemPods }}
            - --v=4
          {{- range $key, $value := .Values.extraArgs }}
            - --{{ $key }}={{ $value }}
          {{- end }}
          env:
            - name: AWS_REGION
              value: "{{ .Values.awsRegion }}"
          ports:
            - containerPort: 8085
          resources:
{{ toYaml .Values.resources | indent 12 }}
          volumeMounts:
            - name: ssl-certs
              mountPath: /etc/ssl/certs/ca-certificates.crt
              readOnly: true
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
      volumes:
        - name: ssl-certs
          hostPath:
            path: /etc/ssl/certs/ca-certificates.crt
