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

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

        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/sarex-inspections:production_1a33f6f4
          pullPolicy:
            _default: IfNotPresent

        deployment:
          enabled: true

          name:
            _default: inspections-backend

          replicaCount:
            _default: 1

          port:
            _default: 8000

          command:
            _default: ["/bin/bash", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/inspections-db ] && . /vault/secrets/inspections-db
                [ -f /vault/secrets/inspections-kafka ] && . /vault/secrets/inspections-kafka
                [ -f /vault/secrets/inspections-django-auth ] && . /vault/secrets/inspections-django-auth
                set +a
                exec ./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: DEBUG
            value:
              _default: "false"

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

          - name: HTTP_APP_HOST
            value:
              _default: "0.0.0.0"

          - name: HTTP_APP_PORT
            value:
              _default: "8000"

          - name: HTTP_APP_ROOT_PATH
            value:
              _default: "/inspections"

          - name: HTTP_APP_WORKERS
            value:
              _default: "3"

          - name: HTTP_APP_ADMIN_ENABLE
            value:
              _default: "true"

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

          - name: KAFKA_EAV_ASSETS_TOPIC
            value:
              _default: "assets_broadcast"

          - name: JWT_AUTH_ENABLE
            value:
              _default: "true"

          - name: NOTIFICATIONS_ENABLE
            value:
              _default: "true"

          - name: NOTIFICATIONS_EMAIL_FROM
            value:
              _default: "hello@sarex.io"

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

          - name: SAREX_BACKEND_TIMEOUT
            value:
              _default: "30"

          - name: EAV_URL
            value:
              _default: "http://eav-service.eav"

          - name: EAV_TIMEOUT
            value:
              _default: "30"

          - name: WORKFLOWS_URL
            value:
              _default: "http://workflows-service.processing-prod"

          - name: WORKFLOWS_TIMEOUT
            value:
              _default: "30"

          - name: WORKFLOWS_EMAIL_DOCKER_IMAGE
            value:
              _default: "cr.yandex/crp3ccidau046kdj8g9q/notification:email"

          - name: MOBILE_APP_CURRENT_VERSION
            value:
              _default: "1.0.0"

          - name: MOBILE_APP_RECOMMENDED_VERSION
            value:
              _default: "1.0.0"

          - name: MOBILE_APP_REQUIRED_VERSION
            value:
              _default: "1.0.0"

          - name: MAILER_URL
            value:
              _default: "http://mailer-service.mailer:8000"

          - name: MAILER_TIMEOUT
            value:
              _default: "30"

        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: inspections
            vault.hashicorp.com/agent-inject-secret-inspections-db: secrets/data/apps/inspections/postgres
            vault.hashicorp.com/agent-inject-template-inspections-db: |-
              {{- with secret "secrets/data/apps/inspections/postgres" -}}
              DATABASE_HOST=postgresql.inspections.svc.cluster.local
              DATABASE_PORT=5432
              DATABASE_NAME=inspections_db
              DATABASE_USER={{ index .Data.data "username" }}
              DATABASE_PASSWORD={{ index .Data.data "password" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-inspections-kafka: secrets/data/kafka/apps/inspections
            vault.hashicorp.com/agent-inject-template-inspections-kafka: |-
              {{- with secret "secrets/data/kafka/apps/inspections" -}}
              KAFKA_HOST={{ index .Data.data.auth "bootstrap_servers" }}
              KAFKA_USERNAME={{ index .Data.data "username" }}
              KAFKA_PASSWORD={{ index .Data.data "password" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-inspections-django-auth: secrets/data/vault/common/django_auth
            vault.hashicorp.com/agent-inject-template-inspections-django-auth: |-
              {{- with secret "secrets/data/vault/common/django_auth" -}}
              SAREX_BACKEND_AUTH={{ index .Data.data "key" }}
              {{- end -}}

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