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

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

        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/bim-api:contour_f9f2a39-dirty
          pullPolicy:
            _default: IfNotPresent

        deployment:
          enabled: true

          name:
            _default: backend

          replicaCount:
            _default: 1

          port:
            _default: 8000

          command:
            _default: ["/bin/sh", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/bim-postgresql ] && . /vault/secrets/bim-postgresql
                set +a
                exec ./httpserver

          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-svc

          type:
            _default: ClusterIP

          port:
            _default: 80

          targetPort:
            _default: 8000

          portName:
            _default: http

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

        envs:
          - name: LAST_MASTER_BIM
            value:
              _default: "100000"

          - name: LAST_MASTER_BIM_V3
            value:
              _default: "100000"

          - name: DB_CERT_PATH_4
            value:
              _default: "/root/yandex_pg.pem"

          - name: DB_CERT_PATH_3
            value:
              _default: "/root/yandex_pg.pem"

          - name: DB_CERT_PATH_2
            value:
              _default: "/root/yandex_pg.pem"

          - name: LAST_SLAVE_1_BIM
            value:
              _default: "1000000"

          - name: POSTGRES_POOL_SIZE
            value:
              _default: "30"

          - name: API_ADDRESS
            value:
              _default: "0.0.0.0:8000"

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

          - name: ENABLE_SQL_QUERY
            value:
              _default: "0"

          - name: ENABLE_SSL
            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: bim
            vault.hashicorp.com/agent-inject-secret-bim-postgresql: secrets/data/apps/bim/postgres
            vault.hashicorp.com/agent-inject-template-bim-postgresql: |-
              {{- with secret "secrets/data/apps/bim/postgres" -}}
              POSTGRES_ADDRESS={{ index .Data.data "host" }}
              POSTGRES_ADDRESS_2={{ index .Data.data "host" }}
              POSTGRES_ADDRESS_3={{ index .Data.data "host" }}
              POSTGRES_ADDRESS_4={{ index .Data.data "host" }}
              POSTGRES_ADDRESS_5={{ index .Data.data "host" }}
              POSTGRES_PORT={{ index .Data.data "port" }}
              POSTGRES_PORT_2={{ index .Data.data "port" }}
              POSTGRES_PORT_3={{ index .Data.data "port" }}
              POSTGRES_PORT_4={{ index .Data.data "port" }}
              POSTGRES_PORT_5={{ index .Data.data "port" }}
              POSTGRES_DB={{ index .Data.data "database" }}
              POSTGRES_DB_2={{ index .Data.data "database" }}
              POSTGRES_DB_3={{ index .Data.data "database" }}
              POSTGRES_DB_4={{ index .Data.data "database" }}
              POSTGRES_DB_5={{ index .Data.data "database" }}
              POSTGRES_USER={{ index .Data.data "username" }}
              POSTGRES_USER_2={{ index .Data.data "username" }}
              POSTGRES_USER_3={{ index .Data.data "username" }}
              POSTGRES_USER_4={{ index .Data.data "username" }}
              POSTGRES_USER_5={{ index .Data.data "username" }}
              POSTGRES_PASSWORD={{ index .Data.data "password" }}
              POSTGRES_PASSWORD_2={{ index .Data.data "password" }}
              POSTGRES_PASSWORD_3={{ index .Data.data "password" }}
              POSTGRES_PASSWORD_4={{ index .Data.data "password" }}
              POSTGRES_PASSWORD_5={{ index .Data.data "password" }}
              {{- end -}}

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