apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "vs.fullname" . }}-cache
  labels:
    {{- include "vs.labels" . | nindent 4 }}
    app.kubernetes.io/service: cache
spec:
  replicas: {{ .Values.cache.replicaCount }}
  selector:
    matchLabels:
      {{- include "vs.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/service: cache
  strategy:
    rollingUpdate:
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "false"
      labels:
        {{- include "vs.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/service: cache
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: {{ .Chart.Name }}-cache
          image: "{{ .Values.cache.image.repository | default "registry.gitlab.eox.at/esa/prism/vs/pvs_cache" }}:{{ .Values.cache.image.tag | default ( print "release-" .Chart.AppVersion ) }}"
          imagePullPolicy: {{ .Values.cache.image.pullPolicy | default "IfNotPresent" }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          startupProbe:
            httpGet:
              path: /
              port: http
            failureThreshold: 30
            periodSeconds: 10
          resources:
            {{- toYaml .Values.cache.resources | nindent 12 }}
          args:
            - /run-httpd.sh
          env:
            {{- range $key, $value := .Values.config.general }}
            - name: {{ $key }}
              value: {{ $value | quote }}
            {{- end }}
            {{- range $key, $value := .Values.config.database }}
            - name: {{ $key }}
              value: {{ $value | quote }}
            {{- end }}
            - name: DB_HOST
              value: {{ .Release.Name }}-database
            {{- range $key, $value := .Values.config.objectStorage.data }}
            - name: {{ $key }}
              value: {{ $value | quote }}
            {{- end }}
            - name: RENDERER_HOST
              value: {{ .Release.Name }}-renderer
            - name: INSTANCE_ID
              value: prism-view-server_cache
            - name: WAIT_SERVICES
              value: "{{ .Release.Name }}-database:{{ .Values.config.database.DB_PORT }} {{ .Release.Name }}-renderer:80"
            - name: WAIT_TIMEOUT
              value: "300"
          volumeMounts:
            - mountPath: /mapcache-template.xml
              name: cache-config.xml
              subPath: cache-config.xml
      {{- with .Values.cache.affinity | default .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
        - configMap:
            items:
              - key: cache-config.xml
                path: cache-config.xml
            name: {{ include "vs.fullname" . }}-cache-config
          name: cache-config
