---
# yaml-language-server: $schema=https://raw.githubusercontent.com/fluxcd-community/flux2-schemas/main/helmrelease-helm-v2beta2.json
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
  name: ingress-nginx
spec:
  interval: 30m
  chart:
    spec:
      chart: ingress-nginx
      version: 4.10.0
      sourceRef:
        kind: HelmRepository
        name: ingress-nginx
        namespace: flux-system
      interval: 30m
  valuesFrom:
    - targetPath: controller.maxmindLicenseKey
      kind: Secret
      name: nginx-external-maxmind-secret
      valuesKey: MAXMIND_LICENSE_KEY
  values:
    controller:
      replicaCount: 2
      updateStrategy:
        type: RollingUpdate
      allowSnippetAnnotations: true
      enableAnnotationValidations: true
      service:
        enabled: true
        type: LoadBalancer
        annotations:
          external-dns.alpha.kubernetes.io/hostname: external.hsn.dev
          io.cilium/lb-ipam-ips: 10.45.0.2

      publishService:
        enabled: true

      metrics:
        enabled: true
        serviceMonitor:
          enabled: true
          namespace: network
          namespaceSelector:
            any: true

      ingressClassResource:
        name: external-nginx
        default: false

      config:
        block-user-agents: "GPTBot,~*GPTBot*,ChatGPT-User,~*ChatGPT-User*,Google-Extended,~*Google-Extended*,CCBot,~*CCBot*,Omgilibot,~*Omgilibot*,FacebookBot,~*FacebookBot*" # taken from https://github.com/superseriousbusiness/gotosocial/blob/main/internal/web/robots.go
        client-body-buffer-size: 100M
        client-body-timeout: 120
        client-header-timeout: 120
        enable-brotli: "true"
        enable-ocsp: "true"
        enable-real-ip: "true"
        hide-headers: Server,X-Powered-By
        hsts-max-age: 31449600
        keep-alive-requests: 10000
        keep-alive: 120
        log-format-escape-json: "true"
        log-format-upstream: >
          {"time": "$time_iso8601", "remote_addr": "$proxy_protocol_addr", "x_forwarded_for": "$proxy_add_x_forwarded_for",
          "request_id": "$req_id", "remote_user": "$remote_user", "bytes_sent": $bytes_sent, "request_time": $request_time,
          "status": $status, "vhost": "$host", "request_proto": "$server_protocol", "path": "$uri", "request_query": "$args",
          "request_length": $request_length, "duration": $request_time, "method": "$request_method", "http_referrer": "$http_referer",
          "http_user_agent": "$http_user_agent", "country_code": "$geoip2_city_country_code", "country_name": "$geoip2_city_country_name"}
        proxy-body-size: 0
        proxy-buffer-size: 16k
        ssl-protocols: TLSv1.3 TLSv1.2
        use-geoip2: true
        use-forwarded-headers: "true"
      extraArgs:
        default-ssl-certificate: "network/hsn-dev-tls"

      topologySpreadConstraints:
        - maxSkew: 2
          topologyKey: kubernetes.io/hostname
          whenUnsatisfiable: DoNotSchedule
          labelSelector:
            matchLabels:
              app.kubernetes.io/instance: ingress-nginx-hsn
              app.kubernetes.io/component: controller

      resources:
        requests:
          cpu: 100m
          memory: 381M

    defaultBackend:
      enabled: false