# 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: qbit-manage
spec:
  interval: 5m
  chart:
    spec:
      chart: app-template
      version: 3.5.1
      sourceRef:
        kind: HelmRepository
        name: bjws-charts
        namespace: flux-system
  values:
    controllers:
      main:
        pod:
          securityContext:
            runAsNonRoot: true
            runAsUser: 10000
            runAsGroup: 10000
            fsGroup: 10000
            fsGroupChangePolicy: OnRootMismatch
        initContainers:
          copy-config:
            image:
              repository: alpine
              tag: 3.210
            command:
            - /bin/sh
            - -c
            - "ls /tmp/config-ro
              && cp -r /tmp/config-ro/. /tmp/config/
              && chmod 777 /tmp/config/config.yml
              && ls /tmp/config"
        containers:
          app:
            image:
              repository: bobokun/qbit_manage
              tag: v4.1.14
            env:
              QBT_STARTUP_DELAY: 45 # seconds
              QBT_SCHEDULE: 720 # 720min = 12hr
          
    persistence:
      storage:
        type: hostPath
        hostPath: /mnt/MainPool/Media/Torrents
        globalMounts:
          - path: /storage/Torrents
      config:
        type: emptyDir
        advancedMounts:
          main: # controller name
            app: # container name
              - path: /config
            copy-config: # container name
              - path: /tmp/config
      # Create tmp mount of configmap that is copied to config.
      #
      # This is done since qbit-manage requires the /config directory to be writable,
      # but ConfigMap mounts are always readonly.
      config-tmp:
        type: configMap
        name: qbit-manage
        items:
          - key: config.yml
            path: config.yml
        advancedMounts:
          main: # controller name
            copy-config: # container name
              - path: /tmp/config-ro