---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: frontend
  namespace: django
spec:
  interval: 5m
  timeout: 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:
      frontend:
        enabled: true

        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/sarex-frontend-dev:cps_82ba823b
          pullPolicy:
            _default: IfNotPresent

        deployment:
          enabled: true

          name:
            _default: frontend

          replicaCount:
            _default: 1

          port:
            _default: 80

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

          probes:
            liveness:
              enabled: false
            readiness:
              enabled: false

        service:
          enabled: true

          name:
            _default: frontend-service

          type:
            _default: ClusterIP

          port:
            _default: 80

          targetPort:
            _default: 80

          portName:
            _default: http

        imagePullSecrets:
          enabled:
            _default: true
          name:
            _default: dockerhub

        # чарт прогоняет weight, key, operator и topologyKey через pluckEnv,
        # который читает только map вида {_default: …}; скаляры дают пустые значения
        affinity:
          podAntiAffinity:
            preferredDuringSchedulingIgnoredDuringExecution:
              - weight:
                  _default: 100
                podAffinityTerm:
                  labelSelector:
                    matchExpressions:
                      - key:
                          _default: app
                        operator:
                          _default: In
                        values:
                          - frontend
                  topologyKey:
                    _default: kubernetes.io/hostname

        # ConfigMap'ы nginx-configmap и robots-txt-config создаются вне этого
        # релиза — чарт только монтирует их
        volumes:
          _default:
            - name: nginx-configmap
              mountPath:
                _default: /etc/nginx/nginx.conf
              subPath:
                _default: nginx.conf
              configMap:
                name:
                  _default: nginx-configmap
                items:
                  - key: nginx.conf
                    path:
                      _default: nginx.conf

            - name: robots-volume
              mountPath:
                _default: /opt/react_client/robots.txt
              subPath:
                _default: robots.txt
              configMap:
                name:
                  _default: robots-txt-config
                items:
                  - key: robots.txt
                    path:
                      _default: robots.txt
