---
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: s3-proxy
  namespace: django
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:
      s3-proxy:
        enabled: true
        serviceAccount:
          enabled:
            _default: true
          name:
            _default: django-vault
        image:
          name:
            _default: cr.yandex/crp3ccidau046kdj8g9q/s3-proxy:vault_6e586217
          pullPolicy:
            _default: Always
        deployment:
          enabled: true
          name:
            _default: s3-proxy
          replicaCount:
            _default: 1
          port:
            _default: 80
          command:
            _default: ["/bin/sh", "-ec"]
          args:
            _default:
              - |
                set -a
                [ -f /vault/secrets/s3 ] && . /vault/secrets/s3
                set +a
                exec /s3-proxy
          probes:
            liveness:
              enabled: false
            readiness:
              enabled: false
        service:
          enabled: true
          name:
            _default: s3-proxy-svc
          type:
            _default: ClusterIP
          port:
            _default: 80
          targetPort:
            _default: 80
          portName:
            _default: http
        envs:
          - name: ACCESS_LOG
            value:
              _default: "true"
          - name: CORS_ALLOW_HEADERS
            value:
              _default: "Content-Type, Accept-Ranges, Content-Range, Content-Encoding"
        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: django
            vault.hashicorp.com/agent-inject-secret-s3: secrets/data/minio/apps/django
            vault.hashicorp.com/agent-inject-template-s3: |
              {{- with secret "secrets/data/minio/apps/django" }}
              AWS_API_ENDPOINT=https://minio.contour.infra.sarex.tech
              {{- $buckets := index .Data.data "buckets" }}
              AWS_S3_BUCKET={{ if gt (len $buckets) 0 }}{{ index (index $buckets 0) "name" }}{{ else }}django{{ end }}
              AWS_ACCESS_KEY_ID={{ index .Data.data "access_key" }}
              AWS_SECRET_ACCESS_KEY={{ index .Data.data "secret_key" }}
              {{- end }}
