---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: documentations-api
  namespace: documentations
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: documentations-vault
        deployment:
          enabled: true
          name:
            _default: documentations-api
          replicaCount:
            _default: 1
          port:
            _default: 8080
          command:
            _default: ["/bin/sh", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/documentations-postgresql ] && . /vault/secrets/documentations-postgresql
                [ -f /vault/secrets/documentations-common ] && . /vault/secrets/documentations-common
                [ -f /vault/secrets/documentations-rsa-public ] && export PUBLIC_KEY="$(cat /vault/secrets/documentations-rsa-public)"
                set +a
                exec /app/entrypoint.sh
          resources:
            requests:
              cpu:
                _default: 25m
              memory:
                _default: 128Mi
          probes:
            liveness:
              enabled: false
            readiness:
              enabled: false
        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/documentations:prod_a9990430
          pullPolicy:
            _default: IfNotPresent
        service:
          enabled: true
          name:
            _default: backend-api-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: "20"
          - name: USE_LEGACY_BIM_FLOW
            value:
              _default: "true"
          - name: ZITADEL_ACCOUNT
            value:
              _default: /vault/secrets/documentations-zitadel-account-json
          - name: ZITADEL_DOMAIN
            value:
              _default: zitadel-srx.wb.ru
          - name: USE_ZITADEL
            value:
              _default: "1"
          - name: FLOWS_URL
            value:
              _default: http://backend-svc.flows.svc.cluster.local:80
          - name: LAST_MASTER_BIM
            value:
              _default: "36311"
          - name: API_ADDRESS
            value:
              _default: 0.0.0.0:8080
          - name: API_ADDRESS_FILE
            value:
              _default: 0.0.0.0:8080
          - name: DOCUMENT_PUBLIC_LINK_JWT_EXPIRATION_MINUTES
            value:
              _default: "5"
          - name: ENABLE_SQL_QUERY
            value:
              _default: "0"
          - name: ENABLE_SSL
            value:
              _default: "0"
          - name: WORKSPACE_V2_EXTERNAL_URL
            value:
              _default: https://sarex.contour.infra.sarex.tech/workspaces-v2/
          - name: ENABLE_S3
            value:
              _default: "1"
          - name: CONTAINER_REGISTRY
            value:
              _default: cr.yandex/crp3ccidau046kdj8g9q
          - name: ENVIRONMENT
            value:
              _default: production
          - name: LAST_SLAVE_1_BIM
            value:
              _default: "1000000"
          - name: HOST
            value:
              _default: http://backend-api-svc.documentations.svc.cluster.local:80
          - name: FILE_STREAM_HOST
            value:
              _default: sarex.contour.infra.sarex.tech
          - name: DOCUMENTATION_URL
            value:
              _default: http://backend-api-svc.documentations.svc.cluster.local:80/
          - name: WORKFLOW_URL
            value:
              _default: http://backend-svc.processing.svc.cluster.local:80/
          - name: WORKSPACE_URL
            value:
              _default: http://backend-svc.workspaces.svc.cluster.local:80/
          - name: BIM_API_URL
            value:
              _default: http://backend-svc.bim.svc.cluster.local:80/
          - name: BIM_API_V2_URL
            value:
              _default: http://backend-svc.bim.svc.cluster.local:80/
          - name: WORKSPACE_BUNDLE_VERSION
            value:
              _default: v1
          - name: SYSTEM_LOG_URL
            value:
              _default: http://backend-svc.system-log.svc.cluster.local:80
          - name: DJANGO_HOST
            value:
              _default: http://backend-svc.django.svc.cluster.local:80
          - name: MARKS_PROCESSING_URL
            value:
              _default: http://marks-service:8000
          - name: PUBLIC_LINK_HOST
            value:
              _default: https://document-link-srx.wb.ru
          - name: NAMESPACE
            value:
              _default: documentations
          - name: DJANGO_ORIGINATOR
            value:
              _default: docs_prod
          - name: WORKFLOW_IMAGES_VERSION
            value:
              _default: master
          - name: WORKFLOWS_IMAGES_VERSION
            value:
              _default: master
          - name: S3_SERVICE_ACCOUNT
            value:
              _default: /vault/secrets/documentations-s3-account-json
          - name: READ_WRITE_TIMEOUT_FILE_STREAM
            value:
              _default: 6h
          - name: CACHE_DEFAULT_EXPIRATION
            value:
              _default: 60s
          - name: ENABLE_SMTP
            value:
              _default: "True"
          - name: ENABLE_MAILGUN
            value:
              _default: "False"
          - name: CACHE_CLEANUP_INTERVAL
            value:
              _default: 60s
          - name: DOCUMENT_PUBLIC_LINK_JWT_SECRET
            value:
              _default: "mock"
          - name: ENABLE_AUTH_JWT_IN_URL
            value:
              _default: "true"
          - name: ENABLE_SIGNATURE_IN_URL
            value:
              _default: "false"
          - name: USE_CACHE_IN_FILE_STREAMER
            value:
              _default: "0"
          - name: VALKEY_ADDR
            value:
              _default: redis:6379
          - name: VALKEY_HOST
            value:
              _default: redis
          - name: VALKEY_PORT
            value:
              _default: "6379"
        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: documentations
            vault.hashicorp.com/agent-inject-secret-documentations-postgresql: secrets/data/apps/documentations/postgres
            vault.hashicorp.com/agent-inject-template-documentations-postgresql: |-
              {{- with secret "secrets/data/apps/documentations/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-documentations-common: secrets/data/vault/common/django_auth
            vault.hashicorp.com/agent-inject-template-documentations-common: |-
              {{- with secret "secrets/data/vault/common/django_auth" -}}
              DJANGO_BASIC_AUTH={{ index .Data.data "key" }}
              DJANGO_BASIC_AUTH_FOR_GET_USER={{ index .Data.data "key" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-documentations-s3-account-json: secrets/data/vault/common/django_auth
            vault.hashicorp.com/agent-inject-template-documentations-s3-account-json: |-
              {{- with secret "secrets/data/vault/common/django_auth" -}}
              {{ index .Data.data "documentations_s3_service_account_json" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-documentations-zitadel-account-json: secrets/data/vault/common/django_auth
            vault.hashicorp.com/agent-inject-template-documentations-zitadel-account-json: |-
              {{- with secret "secrets/data/vault/common/django_auth" -}}
              {{ index .Data.data "documentations_zitadel_account_json" }}
              {{- end -}}
            vault.hashicorp.com/agent-inject-secret-documentations-rsa-public: secrets/data/vault/common/rsa_keys
            vault.hashicorp.com/agent-inject-template-documentations-rsa-public: |-
              {{- with secret "secrets/data/vault/common/rsa_keys" -}}
              {{ index .Data.data "public_key" }}
              {{- end -}}
