---
# ВНИМАНИЕ: envs и args — списки, kustomize заменяет их ЦЕЛИКОМ (JSON merge patch),
# поэтому здесь продублирован весь набор из apps/issues/base/celery.yaml.
# podAnnotations — map, мержится по ключам.
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: celery
  namespace: issues
spec:
  values:
    services:
      celery:
        deployment:
          args:
            _default:
              - |
                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)"
                [ -f /vault/secrets/issues-kafka ] && . /vault/secrets/issues-kafka
                set +a
                exec celery -A config worker -l info -E

        volumes:
          _default:
            - name: production-configmap
              mountPath:
                _default: /src/config/settings/production.py
              subPath:
                _default: production.py
              readOnly:
                _default: true
              configMap:
                name:
                  _default: production-configmap
                items:
                  - key: production.py
                    path:
                      _default: production.py
            - name: kafka-ca-cert
              mountPath:
                _default: /usr/local/share/ca-certificates/kafka.crt
              subPath:
                _default: kafka.crt
              readOnly:
                _default: true
              configMap:
                name:
                  _default: kafka-ca-cert
                items:
                  - key: kafka.crt
                    path:
                      _default: kafka.crt

        envs:
          - name: ENVIRONMENT
            value:
              _default: "production"

          - name: AERO_PUBLIC_HOST
            value:
              _default: "https://srx.wb.ru"

          - name: AERO_HOST
            value:
              _default: "https://srx.wb.ru"

          - name: BASE_AERO_URL
            value:
              _default: "https://srx.wb.ru"

          - name: BASE_AUTH_URL
            value:
              _default: "http://backend-svc.django.svc.cluster.local:80"

          - name: WORKFLOWS_HOST
            value:
              _default: "http://workflows-api-service.workflow.svc.cluster.local:8000"

          - name: WORKFLOWS_URL
            value:
              _default: "http://workflows-api-service.workflow.svc.cluster.local:8000"

          - name: RESOURCES_API_HOST
            value:
              _default: "http://iam-backend.iam.svc.cluster.local:8000"

          - name: EAV_HOST
            value:
              _default: "http://backend-svc.eav.svc.cluster.local:80"

          - name: SAREX_API
            value:
              _default: "https://srx.wb.ru"

          - name: DOCUMENTATIONS_URL
            value:
              _default: "http://backend-api-svc.documentations.svc.cluster.local:80"

          - name: DJANGO_SETTINGS_MODULE
            value:
              _default: "config.settings.production"

          - name: API_ADDRESS
            value:
              _default: "8000"

          # См. подробные комментарии в apps/issues/d8-ugmk-prod/backend-s3.yaml.
          - name: KAFKA_HOST
            value:
              _default: "kafka-kafka-contour.kafka.svc.cluster.local:9092"

          - name: KAFKA_SSL_CAFILE
            value:
              _default: "/usr/local/share/ca-certificates/kafka.crt"

          - name: KAFKA_ISSUES_TOPIC
            value:
              _default: "issues_broadcast_prod"

          - name: KAFKA_EAV_ASSETS_TOPIC
            value:
              _default: "assets_broadcast"

        podAnnotations:
          _default:
            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=sarex-issues
              YC_S3_ENDPOINT_URL=https://s3.uralmine.com
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-issues-kafka: secrets/data/kafka/apps/issues
            vault.hashicorp.com/agent-inject-template-issues-kafka: |-
              {{- with secret "secrets/data/kafka/apps/issues" -}}
              KAFKA_USERNAME={{ index .Data.data "username" }}
              KAFKA_PASSWORD={{ index .Data.data "password" }}
              {{- end -}}
