---
# yaml-language-server: $schema=https://raw.githubusercontent.com/bjw-s/helm-charts/main/charts/other/app-template/schemas/helmrelease-helm-v2.schema.json
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: &app jellyfin
spec:
  interval: 30m
  chart:
    spec:
      chart: app-template
      version: 3.5.1
      sourceRef:
        kind: HelmRepository
        name: bjw-s
        namespace: flux-system
  install:
    remediation:
      retries: 3
  upgrade:
    cleanupOnFail: true
    remediation:
      strategy: rollback
      retries: 3
  dependsOn:
    - name: nvidia-device-plugin
      namespace: kube-system
    - name: node-feature-discovery
      namespace: kube-system
    - name: rook-ceph-cluster
      namespace: rook-ceph
    - name: volsync
      namespace: volsync-system
  values:
    controllers:
      jellyfin:
        annotations:
          reloader.stakater.com/auto: "true"
        containers:
          app:
            image:
              repository: ghcr.io/jellyfin/jellyfin
              tag: 10.10.0@sha256:b15266bad088e3d793401be5845f2453233edd826c02cd7155910055133fb581
            env:
              DOTNET_SYSTEM_IO_DISABLEFILELOCKING: "true"
              JELLYFIN_FFmpeg__probesize: 50000000
              JELLYFIN_FFmpeg__analyzeduration: 50000000
              TZ: America/Chicago
            probes:
              liveness: &probes
                enabled: true
                custom: true
                spec:
                  httpGet:
                    path: /health
                    port: &port 8096
                  initialDelaySeconds: 0
                  periodSeconds: 10
                  timeoutSeconds: 1
                  failureThreshold: 3
              readiness: *probes
              startup:
                enabled: false
            resources:
              requests:
                cpu: 100m
              limits:
                nvidia.com/gpu: 1 # requesting 1 GPU
                memory: 4Gi
    defaultPodOptions:
      securityContext:
        runAsNonRoot: true
        runAsUser: 568
        runAsGroup: 568
        fsGroup: 568
        fsGroupChangePolicy: OnRootMismatch
        supplementalGroups: [44, 10000]
        seccompProfile: { type: RuntimeDefault }
      nodeSelector:
        nvidia.com/gpu.present: "true"
      runtimeClassName: nvidia
    service:
      app:
        controller: *app
        type: LoadBalancer
        annotations:
          io.cilium/lb-ipam-ips: 10.1.1.40
        ports:
          http:
            port: *port
    ingress:
      app:
        annotations:
          external-dns.alpha.kubernetes.io/target: external.hsn.dev
          external-dns.alpha.kubernetes.io/cloudflare-proxied: "true"
        className: external-nginx
        hosts:
          - host: "{{ .Release.Name }}.hsn.dev"
            paths:
              - path: /
                service:
                  identifier: app
                  port: *port
      internal:
        className: internal-nginx
        hosts:
          - host: &host "{{ .Release.Name }}.jahanson.tech"
            paths:
              - path: /
                service:
                  identifier: app
                  port: *port
        tls:
          - hosts:
              - *host
    persistence:
      config:
        enabled: true
        existingClaim: *app
        globalMounts:
          - path: /config
      media:
        type: nfs
        server: shadowfax.jahanson.tech
        path: /moria/media
        globalMounts:
          - path: /media
            readOnly: true
      transcode:
        enabled: true
        type: emptyDir
        globalMounts:
          - path: /transcode
      cache:
        enabled: true
        type: emptyDir
        globalMounts:
          - path: /cache