---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: celery
  namespace: issues
  labels:
    app: celery
    service: celery
spec:
  replicas: 1
  selector:
    matchLabels:
      app: celery
  template:
    metadata:
      labels:
        app: celery
        service: celery
      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: issues
        vault.hashicorp.com/agent-inject-secret-issues-db: secrets/data/postgresql/apps/issues
        vault.hashicorp.com/agent-inject-template-issues-db: |-
          {{- with secret "secrets/data/postgresql/apps/issues" -}}
          DATABASE_PORT=5432
          DATABASE_HOST=postgresql.issues.svc.cluster.local
          DATABASE_USER={{ index .Data.data "username" }}
          DATABASE_PASSWORD={{ index .Data.data "password" }}
          DATABASE_NAME=issues_db
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-issues-rabbitmq: secrets/data/rabbitmq/apps/issues
        vault.hashicorp.com/agent-inject-template-issues-rabbitmq: |-
          {{- with secret "secrets/data/rabbitmq/apps/issues" -}}
          RABBITMQ_VHOST={{ index .Data.data "vhost" }}
          RABBITMQ_USERNAME={{ index .Data.data "username" }}
          RABBITMQ_HOSTNAME=rabbitmq.rabbitmq.svc.cluster.local
          RABBITMQ_PASSWORD={{ index .Data.data "password" }}
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-issues-s3: secrets/data/minio/apps/issues
        vault.hashicorp.com/agent-inject-template-issues-s3: |-
          {{- with secret "secrets/data/minio/apps/issues" -}}
          YC_S3_ACCESS_KEY_ID={{ index .Data.data "access_key" }}
          YC_S3_SECRET_ACCESS_KEY={{ index .Data.data "secret_key" }}
          YC_S3_BUCKET_NAME=rfi
          YC_S3_ENDPOINT_URL=https://minio.contour.infra.sarex.tech
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-issues-django-auth: secrets/data/vault/common/django_auth
        vault.hashicorp.com/agent-inject-template-issues-django-auth: |-
          {{- with secret "secrets/data/vault/common/django_auth" -}}
          DJANGO_TOKEN={{ index .Data.data "key" }}
          SAREX_USERNAME={{ index .Data.data "username" }}
          SAREX_PASSWORD={{ index .Data.data "password" }}
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-issues-jwt-private: secrets/data/vault/common/rsa_keys
        vault.hashicorp.com/agent-inject-template-issues-jwt-private: |-
          {{- with secret "secrets/data/vault/common/rsa_keys" -}}
          {{ index .Data.data "private_key" }}
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-issues-jwt-public: secrets/data/vault/common/rsa_keys
        vault.hashicorp.com/agent-inject-template-issues-jwt-public: |-
          {{- with secret "secrets/data/vault/common/rsa_keys" -}}
          {{ index .Data.data "public_key" }}
          {{- end -}}
    spec:
      serviceAccountName: issues-vault
      volumes:
        - name: production-configmap
          configMap:
            name: production-configmap
            items:
              - key: production.py
                path: production.py
          defaultMode: 420
      containers:
        - name: celery
          image: cr.yandex/crp3ccidau046kdj8g9q/issues:production_17c438aa
          imagePullPolicy: IfNotPresent
          command: ["/bin/sh", "-ec"]
          args:
            - |
              set -a
              [ -f /vault/secrets/issues-db ] && . /vault/secrets/issues-db
              [ -f /vault/secrets/issues-rabbitmq ] && . /vault/secrets/issues-rabbitmq
              [ -f /vault/secrets/issues-s3 ] && . /vault/secrets/issues-s3
              [ -f /vault/secrets/issues-django-auth ] && . /vault/secrets/issues-django-auth
              [ -f /vault/secrets/issues-jwt-private ] && export JWT_PRIVATE_KEY="$(cat /vault/secrets/issues-jwt-private)"
              [ -f /vault/secrets/issues-jwt-public ] && export JWT_PUBLIC_KEY="$(cat /vault/secrets/issues-jwt-public)"
              set +a
              exec celery -A config worker -l info -E
          ports:
            - name: http
              containerPort: 8000
              protocol: TCP
          env:
            - name: ENVIRONMENT
              value: production
            - name: AERO_PUBLIC_HOST
              value: https://srx.wb.ru
            - name: AERO_HOST
              value: https://srx.wb.ru
            - name: BASE_AERO_URL
              value: https://srx.wb.ru
            - name: BASE_AUTH_URL
              value: http://backend-svc.django.svc.cluster.local:80
            - name: WORKFLOWS_HOST
              value: http://workflows-api-service.workflow.svc.cluster.local:8000
            - name: WORKFLOWS_URL
              value: http://workflows-api-service.workflow.svc.cluster.local:8000
            - name: RESOURCES_API_HOST
              value: http://backend-svc.resources.svc.cluster.local:80
            - name: EAV_HOST
              value: http://backend-svc.eav.svc.cluster.local:80
            - name: SAREX_API
              value: https://srx.wb.ru
            - name: DOCUMENTATIONS_URL
              value: http://backend-api-svc.documentations.svc.cluster.local:80
            - name: DJANGO_SETTINGS_MODULE
              value: config.settings.production
            - name: API_ADDRESS
              value: "8000"
          resources:
            requests:
              cpu: "25m"
              memory: 128Mi
          volumeMounts:
            - name: production-configmap
              mountPath: /src/config/settings/production.py
              subPath: production.py
      imagePullSecrets:
        - name: regcred
