apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mercure.fullname" . }}
  labels:
{{ include "mercure.labels" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "mercure.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "mercure.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
        checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      serviceAccountName: {{ template "mercure.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
          readinessProbe:
            httpGet:
              path: /healthz
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          env:
            - name: TRANSPORT_URL
              valueFrom:
                secretKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: transportUrl
            - name: ALLOW_ANONYMOUS
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: allowAnonymous
            - name: SUBSCRIPTIONS
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: subscriptions
            - name: METRICS
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: metrics
            - name: METRICS_LOGIN
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: metricsLogin
            - name: METRICS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: metricsPassword
            - name: CORS_ALLOWED_ORIGINS
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: corsAllowedOrigins
            - name: DEBUG
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: debug
            - name: DEMO
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: demo
            - name: JWT_ALGORITHM
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: jwtAlgorithm
            - name: JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: jwtKey
            - name: LOG_FORMAT
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: logFormat
            - name: PUBLISH_ALLOWED_ORIGINS
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: publishAllowedOrigins
            - name: PUBLISHER_JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: publisherJwtKey
            - name: SUBSCRIBER_JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: subscriberJwtKey
            - name: HEARTBEAT_INTERVAL
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: heartbeatInterval
            - name: READ_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: readTimeout
            - name: WRITE_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: writeTimeout
            - name: DISPATCH_TIMEOUT
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: dispatchTimeout
            - name: COMPRESS
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: compress
            - name: USE_FORWARDED_HEADERS
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: useForwardedHeaders
            - name: SUBSCRIBER_JWT_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: subscriberJwtKey
            - name: LICENSE
              valueFrom:
                secretKeyRef:
                  name: {{ include "mercure.fullname" . }}
                  key: license
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
