---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: backend
  namespace: eav
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: eav-vault
        deployment:
          enabled: true
          name:
            _default: backend
          replicaCount:
            _default: 1
          port:
            _default: 8000
          command:
            _default: ["/bin/sh", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/eav-db ] && . /vault/secrets/eav-db
                [ -f /vault/secrets/eav-s3 ] && . /vault/secrets/eav-s3
                [ -f /vault/secrets/eav-jwt-private ] && export JWT_PRIVATE_KEY="$(cat /vault/secrets/eav-jwt-private)"
                [ -f /vault/secrets/eav-jwt-public ] && export JWT_PUBLIC_KEY="$(cat /vault/secrets/eav-jwt-public)"
                set +a
                exec /server/entrypoint.sh
          resources:
            requests:
              cpu:
                _default: 25m
              memory:
                _default: 100Mi
          probes:
            liveness:
              enabled:
                _default: true
              type:
                _default: tcpSocket
              tcpSocket:
                port:
                  _default: 8000
              initialDelaySeconds:
                _default: 20
              periodSeconds:
                _default: 30
              timeoutSeconds:
                _default: 3
              failureThreshold:
                _default: 5
            readiness:
              enabled:
                _default: true
              type:
                _default: tcpSocket
              tcpSocket:
                port:
                  _default: 8000
              initialDelaySeconds:
                _default: 10
              periodSeconds:
                _default: 10
              timeoutSeconds:
                _default: 3
              failureThreshold:
                _default: 6
        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/eav:prod_0fb73247
          pullPolicy:
            _default: IfNotPresent
        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
        volumes:
          _default:
            - name: django-configmap
              mountPath:
                _default: /server/config/settings/production.py
              subPath:
                _default: production.py
              readOnly:
                _default: true
              configMap:
                name:
                  _default: django-configmap
                items:
                  - key: production.py
                    path:
                      _default: production.py
        envs:
          - name: KAFKA_ENABLED
            value:
              _default: "False"
          - name: ASSETS_TOPIC
            value:
              _default: sarex
          - name: DJANGO_SETTINGS_MODULE
            value:
              _default: config.settings.production
        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: eav
            vault.hashicorp.com/agent-inject-secret-eav-db: secrets/data/apps/eav/postgres
            vault.hashicorp.com/agent-inject-template-eav-db: |-
              {{- with secret "secrets/data/apps/eav/postgres" -}}
              DJANGO_POSTGRES_HOST={{ index .Data.data "host" }}
              DJANGO_POSTGRES_PORT={{ index .Data.data "port" }}
              DJANGO_POSTGRES_DATABASE={{ index .Data.data "database" }}
              DJANGO_POSTGRES_USER={{ index .Data.data "username" }}
              DJANGO_POSTGRES_PASSWORD={{ index .Data.data "password" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-eav-s3: secrets/data/minio/apps/eav
            vault.hashicorp.com/agent-inject-template-eav-s3: |-
              {{- with secret "secrets/data/minio/apps/eav" -}}
              YC_S3_ENDPOINT_URL={{ index .Data.data.client "endpoint" }}
              YC_S3_BUCKET_NAME=eav
              YC_S3_ACCESS_KEY_ID={{ index .Data.data "access_key" }}
              YC_S3_SECRET_ACCESS_KEY={{ index .Data.data "secret_key" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-eav-jwt-private: secrets/data/vault/common/rsa_keys
            vault.hashicorp.com/agent-inject-template-eav-jwt-private: |-
              {{- with secret "secrets/data/vault/common/rsa_keys" -}}
              {{ index .Data.data "private_key" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-eav-jwt-public: secrets/data/vault/common/rsa_keys
            vault.hashicorp.com/agent-inject-template-eav-jwt-public: |-
              {{- with secret "secrets/data/vault/common/rsa_keys" -}}
              {{ index .Data.data "public_key" }}
              {{- end -}}
