---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: workflows-api
  namespace: processing

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

        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/workflows-api_prod:075fc0
          pullPolicy:
            _default: IfNotPresent

        deployment:
          enabled: true

          name:
            _default: workflows-api

          replicaCount:
            _default: 1

          port:
            _default: 8080

          command:
            _default: ["/bin/bash", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/processing-postgresql ] && . /vault/secrets/processing-postgresql
                [ -f /vault/secrets/processing-jwt-public ] && export PUBLIC_KEY="$(cat /vault/secrets/processing-jwt-public)"
                set +a
                exec /httpserver migrate

          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: 8080

          portName:
            _default: http

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

        envs:
          - name: POSTGRES_POOL_SIZE
            value:
              _default: "3"

          - name: HTTP_HOST
            value:
              _default: "0.0.0.0:8080"

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

          - name: S3_SERVICE_ACCOUNT
            value:
              _default: "/etc/sarex/yc-s3/yc-s3-service-account.json"

          - name: ENABLE_SQL_QUERY
            value:
              _default: "0"

          - name: POSTGRES_SSL_USE
            value:
              _default: "0"

        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: processing
            vault.hashicorp.com/agent-inject-secret-processing-postgresql: secrets/data/apps/processing/postgres
            vault.hashicorp.com/agent-inject-template-processing-postgresql: |-
              {{- with secret "secrets/data/apps/processing/postgres" -}}
              POSTGRES_ADDRESS=postgresql.processing.svc.cluster.local
              POSTGRES_PORT=5432
              POSTGRES_USER={{ index .Data.data "username" }}
              POSTGRES_PASSWORD={{ index .Data.data "password" }}
              POSTGRES_DB=workflow_db
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-processing-jwt-public: secrets/data/vault/common/rsa_keys
            vault.hashicorp.com/agent-inject-template-processing-jwt-public: |-
              {{- with secret "secrets/data/vault/common/rsa_keys" -}}
              {{ index .Data.data "public_key" }}
              {{- end -}}

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