apiVersion: apps/v1
kind: Deployment
metadata:
  name: "{{ template "goldfish.fullname" . }}"
  labels:
    app: "{{ template "goldfish.name" . }}"
    release: {{ .Release.Name | quote }}
    heritage: {{ .Release.Service | quote }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: "{{ template "goldfish.name" . }}"
      release: {{ .Release.Name | quote }}
  template:
    metadata:
      labels:
        app: {{ template "goldfish.name" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - containerPort: {{ .Values.service.internalPort }}
          env:
          {{- range $key, $value :=  .Values.secrets }}
          - name: {{ $key | upper | replace "-" "_" }}
            valueFrom:
              secretKeyRef:
                name: {{ template "goldfish.fullname" $ }}
                key: {{ $key }}
          {{- end }}
          livenessProbe:
            httpGet:
              path: /
              port: {{ .Values.service.internalPort }}
          readinessProbe:
            httpGet:
              path: /
              port: {{ .Values.service.internalPort }}
          env:
            - name: GOLDFISH_PORT
              value: {{ .Values.service.internalPort | quote }}
            - name: GOLDFISH_CONFIG
              valueFrom:
                configMapKeyRef:
                  name: {{ template "goldfish.fullname" . }}
                  key: config
            - name: VAULT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: {{ template "goldfish.fullname" . }}
                  key: vault-token
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
