---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: backend
  namespace: rfi
spec:
  interval: 10m
  chart:
    spec:
      chart: universal-chart
      version: "0.1.9"
      sourceRef:
        kind: HelmRepository
        name: yc-oci-charts
        namespace: flux-system
      interval: 10m
  install:
    remediation:
      retries: 3
  upgrade:
    remediation:
      retries: 3
  values:
    global:
      env: _default
    services:
      backend:
        enabled: true
        serviceAccount:
          enabled:
            _default: true
          name:
            _default: rfi-vault
        deployment:
          enabled: true
          name:
            _default: rfi-backend-api
          replicaCount:
            _default: 1
          port:
            _default: 8000
          command:
            _default: ["/bin/sh", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/rfi-db ] && . /vault/secrets/rfi-db
                [ -f /vault/secrets/rfi-s3 ] && . /vault/secrets/rfi-s3
                [ -f /vault/secrets/rfi-rabbitmq ] && . /vault/secrets/rfi-rabbitmq
                [ -f /vault/secrets/rfi-django-auth ] && . /vault/secrets/rfi-django-auth
                set +a
                exec ./entrypoint.sh
          resources:
            requests:
              cpu:
                _default: 25m
              memory:
                _default: 128Mi
          probes:
            liveness:
              enabled: false
            readiness:
              enabled: false
        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/rfi-backend:production_d1e2e80d
          pullPolicy:
            _default: IfNotPresent
        service:
          enabled: true
          name:
            _default: backend-svc
          type:
            _default: ClusterIP
          port:
            _default: 80
          targetPort:
            _default: 8000
          portName:
            _default: http
        imagePullSecrets:
          enabled:
            _default: true
          name:
            _default: regcred
        envs:
          - name: JWT_AUTH_ENABLE
            value:
              _default: "True"
          - name: NOTIFICATIONS_ENABLE
            value:
              _default: "false"
          - name: NOTIFICATIONS_EMAIL_FROM
            value:
              _default: hello@sarex.io
          - name: NOTIFICATIONS_SERVICE_URL
            value:
              _default: https://sarex.contour.infra.sarex.tech/rfi
          - name: SAREX_BACKEND_URL
            value:
              _default: http://backend-svc.django.svc.cluster.local
          - name: EAV_URL
            value:
              _default: http://backend-svc.eav.svc.cluster.local:80
          - name: GATEWAY_URL
            value:
              _default: http://pdm-svc.documentations.svc.cluster.local:80
        podAnnotations:
          _default:
            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: rfi
            vault.hashicorp.com/agent-inject-secret-rfi-db: secrets/data/apps/rfi/postgres
            vault.hashicorp.com/agent-inject-template-rfi-db: |-
              {{- with secret "secrets/data/apps/rfi/postgres" -}}
              DB_HOST={{ index .Data.data "host" }}
              DB_PORT={{ index .Data.data "port" }}
              DB_NAME={{ index .Data.data "database" }}
              DB_USER={{ index .Data.data "username" }}
              DB_PASSWORD={{ index .Data.data "password" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-rfi-s3: secrets/data/minio/apps/rfi
            vault.hashicorp.com/agent-inject-template-rfi-s3: |-
              {{- with secret "secrets/data/minio/apps/rfi" -}}
              YC_S3_ENDPOINT_URL={{ index .Data.data.client "endpoint" }}
              YC_S3_BUCKET_NAME=rfi
              YC_S3_ACCESS_KEY_ID={{ index .Data.data "access_key" }}
              YC_S3_SECRET_ACCESS_KEY={{ index .Data.data "secret_key" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-rfi-rabbitmq: secrets/data/rabbitmq/apps/rfi
            vault.hashicorp.com/agent-inject-template-rfi-rabbitmq: |-
              {{- with secret "secrets/data/rabbitmq/apps/rfi" -}}
              RABBITMQ_VHOST={{ index .Data.data "vhost" }}
              RABBITMQ_USERNAME={{ index .Data.data "username" }}
              RABBITMQ_PASSWORD={{ index .Data.data "password" }}
              RABBITMQ_PORT=5672
              RABBITMQ_HOST=rabbitmq.rabbitmq.svc.cluster.local
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-rfi-django-auth: secrets/data/vault/common/django_auth
            vault.hashicorp.com/agent-inject-template-rfi-django-auth: |-
              {{- with secret "secrets/data/vault/common/django_auth" -}}
              DJANGO_SECRET_KEY={{ index .Data.data "key" }}
              SAREX_BACKEND_AUTH={{ index .Data.data "key" }}
              {{- end -}}
