---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: message-hub
  namespace: message-hub

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: message-hub-vault

        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/message-hub:production_e8010fe4
          pullPolicy:
            _default: IfNotPresent

        deployment:
          enabled: true

          name:
            _default: message-hub

          replicaCount:
            _default: 1

          port:
            _default: 8000

          command:
            _default: ["/bin/bash", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/message-hub-db ] && . /vault/secrets/message-hub-db
                [ -f /vault/secrets/message-hub-s3 ] && . /vault/secrets/message-hub-s3
                [ -f /vault/secrets/message-hub-kafka ] && . /vault/secrets/message-hub-kafka
                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: message-hub-svc

          type:
            _default: ClusterIP

          port:
            _default: 80

          targetPort:
            _default: 80

          portName:
            _default: http

        imagePullSecrets:
          enabled:
            _default: true
          name:
            _default: regcred

        envs:
          - name: WORKER_TIMEOUT
            value:
              _default: "60"

          - name: PYTHONPATH
            value:
              _default: "src"

          - name: SETTINGS_MAX_RETRIES
            value:
              _default: "1"

          - name: SETTINGS_TOPICS
            value:
              _default: '{"planning": "message-hub-prod", "assets":"assets_broadcast","issues": "issues_broadcast_prod", "resources_updated": "iam.resource.updated.v2", "resources_deleted": "iam.resource.deleted.v2"}'

          - name: SETTINGS_PDF_CONVERTER_HOST
            value:
              _default: "http://export-project-service.django.svc.cluster.local:8000"

          - name: SAREX_BASE_HOST
            value:
              _default: "http://backend-service.pm.svc.cluster.local:8000"

          - name: CACHE_HOST
            value:
              _default: "redis.pm.svc.cluster.local"

          - name: CACHE_PORT
            value:
              _default: "6379"

        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: message-hub
            vault.hashicorp.com/agent-inject-secret-message-hub-db: secrets/data/apps/message-hub/postgres
            vault.hashicorp.com/agent-inject-template-message-hub-db: |-
              {{- with secret "secrets/data/apps/message-hub/postgres" -}}
              DB_USERNAME={{ index .Data.data "username" }}
              DB_PASSWORD={{ index .Data.data "password" }}
              DB_DATABASE={{ index .Data.data "database" }}
              DB_HOST={{ index .Data.data "host" }}
              DB_PORT={{ index .Data.data "port" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-message-hub-s3: secrets/data/minio/apps/message-hub
            vault.hashicorp.com/agent-inject-template-message-hub-s3: |-
              {{- with secret "secrets/data/minio/apps/message-hub" -}}
              S3_HOST={{ index .Data.data.client "endpoint" }}
              S3_LOGIN={{ index .Data.data "access_key" }}
              S3_PASSWORD={{ index .Data.data "secret_key" }}
              {{- $buckets := index .Data.data "buckets" }}
              S3_BUCKET={{- if gt (len $buckets) 0 -}}{{ index (index $buckets 0) "name" }}{{- else -}}rfi{{- end -}}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-message-hub-kafka: secrets/data/kafka/apps/pm
            vault.hashicorp.com/agent-inject-template-message-hub-kafka: |-
              {{- with secret "secrets/data/kafka/apps/pm" -}}
              KAFKA_USERNAME={{ index .Data.data "username" }}
              KAFKA_PASSWORD={{ index .Data.data "password" }}
              KAFKA_HOST=kafka-kafka-contour-controller-headless.kafka.svc.cluster.local
              KAFKA_PORT=9094
              KAFKA_SECURITY_PROTOCOL={{ index .Data.data.auth "security_protocol" }}
              KAFKA_SASL_MECHANISM={{ index .Data.data.auth "sasl_mechanism" }}
              {{- end -}}

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