# SPDX-License-Identifier: Apache-2.0
# Copyright 2022 The HuggingFace Authors.

apiVersion: apps/v1
kind: Deployment
metadata:
  labels: {{ include "labels.reverseProxy" . | nindent 4 }}
  name: "{{ include "name" . }}-reverse-proxy"
  namespace: {{ .Release.Namespace }}
spec:
  progressDeadlineSeconds: 600
  replicas: {{ .Values.reverseProxy.replicas }}
  revisionHistoryLimit: 10
  selector:
    matchLabels: {{ include "labels.reverseProxy" . | nindent 6 }}
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels: {{ include "labels.reverseProxy" . | nindent 8 }}
      annotations:
        co.elastic.logs/json.expand_keys: "true"
        checksum/config: {{ include (print $.Template.BasePath "/reverse-proxy/configMap.yaml") . | sha256sum }}
    spec:
      {{- include "image.imagePullSecrets" . | nindent 6 }}
      initContainers: 
        {{ include "initContainerAssets" . | nindent 8 }}
        {{ include "initContainerCachedAssets" . | nindent 8 }}
      containers: {{ include "containerReverseProxy" . | nindent 8 }}
      nodeSelector: {{ toYaml .Values.reverseProxy.nodeSelector | nindent 8 }}
      tolerations: {{ toYaml .Values.reverseProxy.tolerations | nindent 8 }}
      volumes:
      {{ include "volumeData" . | nindent 6 }}
      - name: nginx-templates
        configMap:
          name: "{{ include "name" . }}-reverse-proxy"
          defaultMode: 420
          optional: false
          items:
            - key: "default.conf.template"
              path: "default.conf.template"
      - name: error-pages
        configMap:
          name: "{{ include "name" . }}-reverse-proxy"
          defaultMode: 420
          optional: false
          items:
            - key: "404.html"
              path: "404.html"
      - name: static-files
        configMap:
          name: "{{ include "name" . }}-reverse-proxy"
          defaultMode: 420
          optional: false
          items:
            - key: "openapi.json"
              path: "openapi.json"
