apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ include "common.fullname" . }}
  labels:
{{ include "common.labels.standard" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "common.name" . }}
      release: {{ .Release.Name | quote }}
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: {{ template "common.name" . }}
        release: {{ .Release.Name | quote }}
{{- if .Values.annotations }}
      annotations:
{{ toYaml .Values.annotations | indent 8 }}
{{- end }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
{{- range $name, $value := .Values.env }}
{{- if not (empty $value) }}
            - name: {{ $name | quote }}
              value: {{ $value | quote }}
{{- end }}
{{- end }}
{{- $secret_name := include "common.fullname" . }}
{{- range $name, $value := .Values.secrets }}
{{- if not ( empty $value) }}
            - name: {{ $name | quote }}
              valueFrom:
                secretKeyRef:
                  name: {{ $secret_name }}
                  key: {{ $name | quote }}
{{- end }}
{{- end }}
          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 }}
