---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: backend
  namespace: workspaces
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: workspaces-vault
        deployment:
          enabled: true
          name:
            _default: workspaces-api
          replicaCount:
            _default: 1
          port:
            _default: 8000
          command:
            _default: ["/bin/sh", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/workspaces-db ] && . /vault/secrets/workspaces-db
                [ -f /vault/secrets/workspaces-django-auth ] && . /vault/secrets/workspaces-django-auth
                set +a
                exec /api
          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
        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/workspaces:production_bfd943b2
          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
        envs:
          - name: POSTGRES_POOL_SIZE
            value:
              _default: "3"
          - name: BUNDLES_RETRY_COUNT
            value:
              _default: "5"
          - name: BUNDLES_NJOBS
            value:
              _default: "5"
          - name: API_ADDRESS
            value:
              _default: 0.0.0.0:8000
          - name: NAMESPACE
            value:
              _default: workspaces
          - name: ENABLE_SQL_QUERY
            value:
              _default: "0"
          - name: ENABLE_SSL
            value:
              _default: "0"
          - name: DOCUMENTATION_HOST
            value:
              _default: http://backend-api-svc.documentations.svc.cluster.local:80
          - name: DOCUMENTATION_LOGGER_FEATURE
            value:
              _default: "0"
          - name: DOCUMENTATION_ORIGINATOR
            value:
              _default: prod_ws
          - name: ENVIRONMENT
            value:
              _default: prod
          - name: DJANGO_HOST
            value:
              _default: http://backend.django.svc.cluster.local:8000
          - name: DJANGO_ORIGINATOR
            value:
              _default: docs_prod
        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: workspaces
            vault.hashicorp.com/agent-inject-secret-workspaces-db: secrets/data/apps/workspaces/postgres
            vault.hashicorp.com/agent-inject-template-workspaces-db: |-
              {{- with secret "secrets/data/apps/workspaces/postgres" -}}
              POSTGRES_ADDRESS={{ index .Data.data "host" }}
              POSTGRES_PORT={{ index .Data.data "port" }}
              POSTGRES_DB={{ index .Data.data "database" }}
              POSTGRES_USER={{ index .Data.data "username" }}
              POSTGRES_PASSWORD={{ index .Data.data "password" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-workspaces-django-auth: secrets/data/vault/common/django_auth
            vault.hashicorp.com/agent-inject-template-workspaces-django-auth: |-
              {{- with secret "secrets/data/vault/common/django_auth" -}}
              DJANGO_BASIC_AUTH={{ index .Data.data "key" }}
              {{- end -}}
