---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: backend
  namespace: flows

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: flows-vault

        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/flows-backend:production_2a439111
          pullPolicy:
            _default: IfNotPresent

        deployment:
          enabled: true

          name:
            _default: backend

          replicaCount:
            _default: 1

          port:
            _default: 8000

          command:
            _default: ["/bin/sh", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/flows-postgresql ] && . /vault/secrets/flows-postgresql
                [ -f /vault/secrets/flows-rabbitmq ] && . /vault/secrets/flows-rabbitmq
                [ -f /vault/secrets/flows-django-auth ] && . /vault/secrets/flows-django-auth
                [ -f /vault/secrets/flows-jwt-public ] && export JWT_PUBLIC_KEY="$(cat /vault/secrets/flows-jwt-public)"
                set +a
                exec /opt/entrypoint.sh

          resources:
            requests:
              cpu:
                _default: 25m
              memory:
                _default: 128Mi

          probes:
            liveness:
              enabled: false
            readiness:
              enabled: false

        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: LOG_LEVEL
            value:
              _default: "DEBUG"

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

          - name: CELERY_QUEUE
            value:
              _default: "flow"

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

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

          - name: PLANNING_HOST
            value:
              _default: "http://backend-svc.pm.svc.cluster.local:80/api/pm/msp"

          - name: PLANNING_USE
            value:
              _default: "True"

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

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

          - name: ENABLE_ANALYTICS
            value:
              _default: "1"

          - name: ENABLE_CELERY
            value:
              _default: "1"

          - name: ENABLE_MAILGUN
            value:
              _default: "0"

          - name: ENABLE_METRICS
            value:
              _default: "0"

          - name: FROM_EMAIL
            value:
              _default: "sarex@rwb.ru"

          - name: GATEWAY_URL
            value:
              _default: "http://pdm-api.documentations.svc.cluster.local:8080"

          - name: RESOURCE_URL
            value:
              _default: "http://resources-service.resources.svc.cluster.local:8000"

          - name: SERVICE_HOST
            value:
              _default: "https://srx.wb.ru/flows/api/v1"

          - name: SMTP_HOST
            value:
              _default: "mail.rwb.ru"

          - name: CHECKLIST_HOST
            value:
              _default: "http://checklists-backend-service.checklists.svc.cluster.local:80"

          - name: SMTP_PORT
            value:
              _default: "465"

          - name: SYNC_RESOURCE_ID
            value:
              _default: "1"

          - name: TIMEOUT
            value:
              _default: "120"

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

          - name: WORKFLOWS_TIMEOUT
            value:
              _default: "60"

          - name: DOCUMENTATION_TIMEOUT
            value:
              _default: "60"

        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: flows
            vault.hashicorp.com/agent-inject-secret-flows-postgresql: secrets/data/apps/flows/postgres
            vault.hashicorp.com/agent-inject-template-flows-postgresql: |-
              {{- with secret "secrets/data/apps/flows/postgres" -}}
              PG_DB={{ index .Data.data "database" }}
              PG_LOGIN={{ index .Data.data "username" }}
              PG_HOST={{ index .Data.data "host" }}
              PG_PORT={{ index .Data.data "port" }}
              PG_PASSWORD={{ index .Data.data "password" }}
              DOCUMENTATION_PG_HOST=postgresql.flows.svc.cluster.local
              DOCUMENTATION_PG_PORT=5432
              DOCUMENTATION_PG_DATABASE=flows_db
              DOCUMENTATION_PG_USERNAME={{ index .Data.data "username" }}
              DOCUMENTATION_PG_PASSWORD={{ index .Data.data "password" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-flows-rabbitmq: secrets/data/rabbitmq/apps/flows
            vault.hashicorp.com/agent-inject-template-flows-rabbitmq: |-
              {{- with secret "secrets/data/rabbitmq/apps/flows" -}}
              RABBITMQ_USERNAME={{ index .Data.data "username" }}
              RABBITMQ_PASSWORD={{ index .Data.data "password" }}
              RABBITMQ_VHOST={{ index .Data.data "vhost" }}
              RABBITMQ_HOST=rabbitmq.rabbitmq.svc.cluster.local
              RABBITMQ_PORT=5672
              ADMIN_PANEL_SECRET_KEY=rabbitmq.rabbitmq:5672
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-flows-django-auth: secrets/data/vault/common/django_auth
            vault.hashicorp.com/agent-inject-template-flows-django-auth: |-
              {{- with secret "secrets/data/vault/common/django_auth" -}}
              DJANGO_TOKEN={{ index .Data.data "key" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-flows-jwt-public: secrets/data/vault/common/rsa_keys
            vault.hashicorp.com/agent-inject-template-flows-jwt-public: |-
              {{- with secret "secrets/data/vault/common/rsa_keys" -}}
              {{ index .Data.data "public_key" }}
              {{- end -}}

        commitSha: ""
        gitlabUri: ""
        gitlabJobUrl: ""
        owner: ""
