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

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

        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/mapper:prod_b0d05a34
          pullPolicy:
            _default: IfNotPresent

        deployment:
          enabled: true

          name:
            _default: backend

          replicaCount:
            _default: 3

          port:
            _default: 8000

          command:
            _default: ["/bin/bash", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/mapper-django-auth ] && . /vault/secrets/mapper-django-auth
                [ -f /vault/secrets/mapper-db ] && . /vault/secrets/mapper-db
                [ -f /vault/secrets/mapper-rabbitmq ] && . /vault/secrets/mapper-rabbitmq
                [ -f /vault/secrets/mapper-s3 ] && . /vault/secrets/mapper-s3
                [ -f /vault/secrets/mapper-kafka ] && . /vault/secrets/mapper-kafka
                set +a
                exec /bin/bash /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: DOCUMENTATION_HOST
            value:
              _default: "https://api.sarex.io/documentations/api/v1"

          - name: FLOW_HOST
            value:
              _default: "https://api.sarex.io/flows/api/v1"

          - name: DJANGO_HOST
            value:
              _default: "https://lk.sarex.io/api"

          - name: NOTE_HOST
            value:
              _default: "https://api.sarex.io/notes/api/v1"

          - name: REDIS_USE
            value:
              _default: "0"

          - name: TIMEOUT
            value:
              _default: "120"

        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: mapper
            vault.hashicorp.com/agent-inject-secret-mapper-django-auth: secrets/data/vault/common/django_auth
            vault.hashicorp.com/agent-inject-template-mapper-django-auth: |-
              {{- with secret "secrets/data/vault/common/django_auth" -}}
              MAPPER_DJANGO_TOKEN={{ index .Data.data "key" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-mapper-db: secrets/data/apps/mapper/postgres
            vault.hashicorp.com/agent-inject-template-mapper-db: |-
              {{- with secret "secrets/data/apps/mapper/postgres" -}}
              MAPPER_DB_USER={{ index .Data.data "username" }}
              MAPPER_DB_PASSWORD={{ index .Data.data "password" }}
              MAPPER_DB_HOST={{ index .Data.data "host" }}
              MAPPER_DB_PORT={{ index .Data.data "port" }}
              MAPPER_DB_NAME={{ index .Data.data "database" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-mapper-rabbitmq: secrets/data/rabbitmq/apps/mapper
            vault.hashicorp.com/agent-inject-template-mapper-rabbitmq: |-
              {{- with secret "secrets/data/rabbitmq/apps/mapper" -}}
              MAPPER_RABBITMQ_VHOST={{ index .Data.data "vhost" }}
              MAPPER_RABBITMQ_USERNAME={{ index .Data.data "username" }}
              MAPPER_RABBITMQ_PASSWORD={{ index .Data.data "password" }}
              MAPPER_RABBITMQ_HOST=rabbitmq.rabbitmq.svc.cluster.local
              MAPPER_RABBITMQ_PORT=5672
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-mapper-s3: secrets/data/minio/apps/mapper
            vault.hashicorp.com/agent-inject-template-mapper-s3: |-
              {{- with secret "secrets/data/minio/apps/mapper" -}}
              MAPPER_S3_ENDPOINT={{ index .Data.data.client "endpoint" }}
              MAPPER_S3_REGION={{ index .Data.data.client "region" }}
              MAPPER_S3_BUCKET=mapper
              MAPPER_S3_ACCESS_KEY_ID={{ index .Data.data "access_key" }}
              MAPPER_S3_SECRET_ACCESS_KEY={{ index .Data.data "secret_key" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-mapper-kafka: secrets/data/kafka/apps/mapper
            vault.hashicorp.com/agent-inject-template-mapper-kafka: |-
              {{- with secret "secrets/data/kafka/apps/mapper" -}}
              MAPPER_KAFKA_BOOTSTRAP_SERVERS={{ index .Data.data.auth "bootstrap_servers" }}
              MAPPER_KAFKA_SECURITY_PROTOCOL={{ index .Data.data.auth "security_protocol" }}
              MAPPER_KAFKA_SASL_MECHANISM={{ index .Data.data.auth "sasl_mechanism" }}
              MAPPER_KAFKA_USERNAME={{ index .Data.data "username" }}
              MAPPER_KAFKA_PASSWORD={{ index .Data.data "password" }}
              {{- end -}}

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