apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "veylant-proxy.fullname" . }}
  labels:
    {{- include "veylant-proxy.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "veylant-proxy.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "veylant-proxy.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/slot: {{ .Values.slot | default "blue" }}
    spec:
      serviceAccountName: {{ include "veylant-proxy.serviceAccountName" . }}
      containers:
        - name: proxy
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          env:
            - name: VEYLANT_SERVER_PORT
              value: "{{ .Values.service.port }}"
            - name: VEYLANT_PROVIDERS_OPENAI_API_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ .Values.secrets.openaiApiKeySecretName }}
                  key: {{ .Values.secrets.openaiApiKeySecretKey }}
            - name: VEYLANT_DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: {{ .Values.secrets.databaseUrlSecretName }}
                  key: {{ .Values.secrets.databaseUrlSecretKey }}
          volumeMounts:
            - name: config
              mountPath: /config.yaml
              subPath: config.yaml
              readOnly: true
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 5
            periodSeconds: 10
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 3
            periodSeconds: 5
            failureThreshold: 3
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      volumes:
        - name: config
          configMap:
            name: {{ include "veylant-proxy.fullname" . }}-config
