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

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

        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/comparisons_backend_prod:075fc0
          pullPolicy:
            _default: IfNotPresent

        deployment:
          enabled: true

          name:
            _default: backend

          replicaCount:
            _default: 1

          port:
            _default: 8000

          command:
            _default: ["/bin/bash", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/comparisons-db ] && . /vault/secrets/comparisons-db
                [ -f /vault/secrets/comparisons-jwt-public ] && export AUTH_PUBLIC_KEY="$(cat /vault/secrets/comparisons-jwt-public)"
                set +a
                exec /app/entrypoint.sh

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

          probes:
            liveness:
              enabled:
                _default: true
              type:
                _default: httpGet
              httpGet:
                path:
                  _default: /ping
                port:
                  _default: 8000
              initialDelaySeconds:
                _default: 10
              periodSeconds:
                _default: 60
              failureThreshold:
                _default: 10
            readiness:
              enabled:
                _default: true
              type:
                _default: httpGet
              httpGet:
                path:
                  _default: /ping
                port:
                  _default: 8000
              initialDelaySeconds:
                _default: 5
              periodSeconds:
                _default: 5
              failureThreshold:
                _default: 20

        service:
          enabled: true

          name:
            _default: backend-service

          type:
            _default: ClusterIP

          port:
            _default: 8000

          targetPort:
            _default: 8000

          portName:
            _default: http

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

        volumes:
          _default:
            - name: tasks-execution-config
              mountPath:
                _default: /etc/app/tasks-execution-config.json
              subPath:
                _default: tasks-execution-config.json
              readOnly:
                _default: true
              configMap:
                name:
                  _default: tasks-execution-config-comparisons-v2
                items:
                  - key: tasks-execution-config-comparisons-v2.json
                    path:
                      _default: tasks-execution-config.json

        envs:
          - name: APP_NAME
            value:
              _default: "comparisons"

          - name: APP_VERSION
            value:
              _default: "0.0.1"

          - name: LOGGER_LOG_LEVEL
            value:
              _default: "info"

          - name: DATABASE_NAME
            value:
              _default: "postgres"

          - name: ENABLE_SSL
            value:
              _default: "false"

          - name: POSTGRES_POOL_SIZE
            value:
              _default: "10"

          - name: HTTP_PORT
            value:
              _default: "8000"

          - name: DOCUMENTATIONS_INTERNAL_HOST
            value:
              _default: "http://documentations-service.documentations"

          - name: DOCUMENTATIONS_EXTERNAL_HOST
            value:
              _default: "https://api.sarex.io/documentations"

          - name: DOCUMENTATION_FILESTREAM_URL
            value:
              _default: "http://backend-filestream-svc.documentations.svc.cluster.local/"

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

          - name: WORKFLOWS_IMAGE_VERSION
            value:
              _default: "master"

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

          - name: WORKFLOWS_BIMV2_INTERNAL_HOST
            value:
              _default: "http://bim-backend-v2-service.bim-api"

          - name: WORKSPACES_HOST
            value:
              _default: "http://workspaces-service.workspaces"

          - name: EAV_HOST
            value:
              _default: "https://api.sarex.io/eav"

          - name: LAST_MASTER_BIM
            value:
              _default: "36311"

          - name: LAST_SLAVE_1_BIM
            value:
              _default: "94015"

          - name: LAST_SLAVE_2_BIM
            value:
              _default: "135771"

          - name: ABAP_FIXED_CONC
            value:
              _default: "0"

          - name: WORKFLOWS_CONFIG_FILEPATH
            value:
              _default: "/etc/app/tasks-execution-config.json"

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

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