---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
  namespace: transmittal
  labels:
    app: backend
    service: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
        service: backend
      annotations:
        traffic.sidecar.istio.io/excludeOutboundPorts: "8200"
        vault.hashicorp.com/agent-init-first: "true"
        vault.hashicorp.com/agent-inject: "true"
        vault.hashicorp.com/agent-pre-populate-only: "true"
        vault.hashicorp.com/auth-path: auth/kubernetes
        vault.hashicorp.com/role: transmittal
        vault.hashicorp.com/agent-inject-secret-transmittal-db: secrets/data/postgresql/apps/transmittal
        vault.hashicorp.com/agent-inject-template-transmittal-db: |-
          {{- with secret "secrets/data/postgresql/apps/transmittal" -}}
          TRANSMITTAL_SERVICE_DATABASE__USER={{ index .Data.data "username" }}
          TRANSMITTAL_SERVICE_DATABASE__PASSWORD={{ index .Data.data "password" }}
          TRANSMITTAL_SERVICE_DATABASE__HOST=postgresql.transmittal.svc.cluster.local
          TRANSMITTAL_SERVICE_DATABASE__PORT=5432
          TRANSMITTAL_SERVICE_DATABASE__NAME=transmittal_db
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-transmittal-rabbitmq: secrets/data/rabbitmq/apps/transmittal
        vault.hashicorp.com/agent-inject-template-transmittal-rabbitmq: |-
          {{- with secret "secrets/data/rabbitmq/apps/transmittal" -}}
          TRANSMITTAL_SERVICE_RABBITMQ__USER={{ index .Data.data "username" }}
          TRANSMITTAL_SERVICE_RABBITMQ__PASSWORD={{ index .Data.data "password" }}
          TRANSMITTAL_SERVICE_RABBITMQ__VHOST={{ index .Data.data "vhost" }}
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-transmittal-s3: secrets/data/minio/apps/transmittal
        vault.hashicorp.com/agent-inject-template-transmittal-s3: |-
          {{- with secret "secrets/data/minio/apps/transmittal" -}}
          TRANSMITTAL_SERVICE_S3_CLIENT__ACCESS_KEY={{ index .Data.data "access_key" }}
          TRANSMITTAL_SERVICE_S3_CLIENT__SECRET_KEY={{ index .Data.data "secret_key" }}
          {{- $buckets := index .Data.data "buckets" }}
          TRANSMITTAL_SERVICE_S3_CLIENT__DEFAULT_BUCKET={{- if gt (len $buckets) 0 -}}{{ index (index $buckets 0) "name" }}{{- else -}}transmittal-storage{{- end -}}
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-transmittal-django-auth: secrets/data/vault/common/django_auth
        vault.hashicorp.com/agent-inject-template-transmittal-django-auth: |-
          {{- with secret "secrets/data/vault/common/django_auth" -}}
          TRANSMITTAL_SERVICE_SAREX_BACKEND_REPOSITORY__BASIC_AUTH_ENCODED={{ index .Data.data "key" }}
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-transmittal-public-key: secrets/data/vault/common/rsa_keys
        vault.hashicorp.com/agent-inject-template-transmittal-public-key: |-
          {{- with secret "secrets/data/vault/common/rsa_keys" -}}
          TRANSMITTAL_SERVICE_AUTH__PUBLIC_KEY={{ printf "%q" (index .Data.data "public_key") }}
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-transmittal-mailgun: secrets/data/vault/apps/transmittal
        vault.hashicorp.com/agent-inject-template-transmittal-mailgun: |-
          {{- with secret "secrets/data/vault/apps/transmittal" -}}
          TRANSMITTAL_SERVICE_MAILGUN__API_KEY={{ index .Data.data "TRANSMITTAL_SERVICE_MAILGUN__API_KEY" }}
          {{- end -}}
    spec:
      serviceAccountName: transmittal-vault
      containers:
        - name: backend
          image: cr.yandex/crp3ccidau046kdj8g9q/transmittal-api:prod_a9d879ae
          imagePullPolicy: IfNotPresent
          command: ["/bin/bash", "-ec"]
          args:
            - |
              set -a
              [ -f /vault/secrets/transmittal-db ] && . /vault/secrets/transmittal-db
              [ -f /vault/secrets/transmittal-rabbitmq ] && . /vault/secrets/transmittal-rabbitmq
              [ -f /vault/secrets/transmittal-s3 ] && . /vault/secrets/transmittal-s3
              [ -f /vault/secrets/transmittal-django-auth ] && . /vault/secrets/transmittal-django-auth
              [ -f /vault/secrets/transmittal-public-key ] && . /vault/secrets/transmittal-public-key
              [ -f /vault/secrets/transmittal-mailgun ] && . /vault/secrets/transmittal-mailgun
              set +a
              exec scripts/entrypoint.sh
          ports:
            - name: http
              containerPort: 8000
              protocol: TCP
          env:
            - name: TRANSMITTAL_SERVICE_APP__NAME
              value: Transmittal Service
            - name: TRANSMITTAL_SERVICE_APP__LOG_LEVEL
              value: ERROR
            - name: TRANSMITTAL_SERVICE_FLOWS_REPOSITORY__BASE_URL
              value: http://backend-svc.flows.svc.cluster.local:80
            - name: TRANSMITTAL_SERVICE_FLOWS_REPOSITORY__MAX_CONNECTIONS
              value: "10"
            - name: TRANSMITTAL_SERVICE_FLOWS_REPOSITORY__MAX_KEEPALIVE_CONNECTIONS
              value: "5"
            - name: TRANSMITTAL_SERVICE_FLOWS_REPOSITORY__TIMEOUT
              value: "30"
            - name: TRANSMITTAL_SERVICE_APP__HOST
              value: https://sarex.contour.infra.sarex.tech/transmittal
            - name: TRANSMITTAL_SERVICE_APP__ENVIRONMENT
              value: prod
            - name: TRANSMITTAL_SERVICE_CORS__ALLOW_ORIGINS
              value: '["*"]'
            - name: TRANSMITTAL_SERVICE_CORS__ALLOW_METHODS
              value: '["*"]'
            - name: TRANSMITTAL_SERVICE_CORS__ALLOW_HEADERS
              value: '["*"]'
            - name: TRANSMITTAL_SERVICE_CORS__ALLOW_CREDENTIALS
              value: "true"
            - name: TRANSMITTAL_SERVICE_UVICORN__HOST
              value: 0.0.0.0
            - name: TRANSMITTAL_SERVICE_UVICORN__PORT
              value: "8000"
            - name: TRANSMITTAL_SERVICE_UVICORN__ENABLE_AUTO_RELOAD
              value: "false"
            - name: TRANSMITTAL_SERVICE_OTEL__ENABLE
              value: "false"
            - name: TRANSMITTAL_SERVICE_OTEL__HOST
              value: http://signoz-otel-collector-external.signoz.svc.cluster.local:4317
            - name: TRANSMITTAL_SERVICE_OTEL__SERVICE_NAME
              value: backend.transmittals-prod
            - name: TRANSMITTAL_SERVICE_OTEL__INSECURE
              value: "false"
            - name: TRANSMITTAL_SERVICE_DATABASE__SSL_MODE
              value: verify-full
            - name: TRANSMITTAL_SERVICE_DATABASE__SSL_ROOT_CERT_PATH
              value: /opt/.postgresql/root.crt
            - name: TRANSMITTAL_SERVICE_UVICORN__LOG_LEVEL
              value: info
            - name: TRANSMITTAL_SERVICE_UVICORN__NUM_WORKERS
              value: "2"
            - name: TRANSMITTAL_SERVICE_UVICORN__ROOT_PATH
            - name: TRANSMITTAL_SERVICE_DATABASE__ENABLE_SSL
              value: "false"
            - name: TRANSMITTAL_SERVICE_RABBITMQ__HOST
              value: rabbitmq.rabbitmq.svc.cluster.local
            - name: TRANSMITTAL_SERVICE_RABBITMQ__PORT
              value: "5672"
            - name: TRANSMITTAL_SERVICE_SAREX_BACKEND_REPOSITORY__BASE_URL
              value: http://backend-svc.django.svc.cluster.local:80
            - name: TRANSMITTAL_SERVICE_SAREX_BACKEND_REPOSITORY__MAX_CONNECTIONS
              value: "10"
            - name: TRANSMITTAL_SERVICE_SAREX_BACKEND_REPOSITORY__MAX_KEEPALIVE_CONNECTIONS
              value: "5"
            - name: TRANSMITTAL_SERVICE_SAREX_BACKEND_REPOSITORY__TIMEOUT
              value: "15"
            - name: TRANSMITTAL_SERVICE_RESOURCE_REPOSITORY__BASE_URL
              value: http://backend-svc.resources.svc.cluster.local:80
            - name: TRANSMITTAL_SERVICE_RESOURCE_REPOSITORY__MAX_CONNECTIONS
              value: "10"
            - name: TRANSMITTAL_SERVICE_RESOURCE_REPOSITORY__MAX_KEEPALIVE_CONNECTIONS
              value: "5"
            - name: TRANSMITTAL_SERVICE_RESOURCE_REPOSITORY__TIMEOUT
              value: "15"
            - name: TRANSMITTAL_SERVICE_DOCUMENTATIONS_REPOSITORY__BASE_URL
              value: http://documentations-api.documentations.svc.cluster.local:8080
            - name: TRANSMITTAL_SERVICE_DOCUMENTATIONS_REPOSITORY__MAX_CONNECTIONS
              value: "10"
            - name: TRANSMITTAL_SERVICE_DOCUMENTATIONS_REPOSITORY__MAX_KEEPALIVE_CONNECTIONS
              value: "5"
            - name: TRANSMITTAL_SERVICE_DOCUMENTATIONS_REPOSITORY__TIMEOUT
              value: "15"
            - name: TRANSMITTAL_SERVICE_S3_CLIENT__MAX_POOL_CONNECTIONS
              value: "10"
            - name: TRANSMITTAL_SERVICE_S3_CLIENT__CONNECT_TIMEOUT
              value: "10"
            - name: TRANSMITTAL_SERVICE_S3_CLIENT__READ_TIMEOUT
              value: "50"
            - name: TRANSMITTAL_SERVICE_S3_CLIENT__REGION_NAME
              value: ru-central1
            - name: TRANSMITTAL_SERVICE_S3_CLIENT__VERIFY
              value: "true"
            - name: TRANSMITTAL_SERVICE_S3_CLIENT__ENDPOINT
              value: minio.minio.svc.cluster.local:9000
            - name: TRANSMITTAL_SERVICE_S3_CLIENT__USE_SSL
              value: "false"
            - name: TRANSMITTAL_SERVICE_HTML_TO_PDF_CONVERTER__BASE_URL
              value: http://export-project-service.django.svc.cluster.local:8000
            - name: TRANSMITTAL_SERVICE_HTML_TO_PDF_CONVERTER__MAX_CONNECTIONS
              value: "10"
            - name: TRANSMITTAL_SERVICE_HTML_TO_PDF_CONVERTER__MAX_KEEPALIVE_CONNECTIONS
              value: "5"
            - name: TRANSMITTAL_SERVICE_HTML_TO_PDF_CONVERTER__TIMEOUT
              value: "50"
            - name: TRANSMITTAL_SERVICE_MARKINGS__BASE_URL
              value: http://marks-service.documentations.svc.cluster.local:8000
            - name: TRANSMITTAL_SERVICE_MARKINGS__MAX_CONNECTIONS
              value: "10"
            - name: TRANSMITTAL_SERVICE_MARKINGS__MAX_KEEPALIVE_CONNECTIONS
              value: "5"
            - name: TRANSMITTAL_SERVICE_MARKINGS__TIMEOUT
              value: "50"
            - name: TRANSMITTAL_SERVICE_MAILGUN__BASE_URL
              value: https://api.mailgun.net/v3/mg.sarex.io
            - name: TRANSMITTAL_SERVICE_MAILGUN__MAX_CONNECTIONS
              value: "10"
            - name: TRANSMITTAL_SERVICE_MAILGUN__MAX_KEEPALIVE_CONNECTIONS
              value: "5"
            - name: TRANSMITTAL_SERVICE_MAILGUN__TIMEOUT
              value: "15"
            - name: TRANSMITTAL_SERVICE_MAILGUN__EMAIL
              value: hello@wb.io
          resources:
            requests:
              cpu: "25m"
              memory: 128Mi
      imagePullSecrets:
        - name: regcred
