---
# 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: plex-image-cleanup
spec:
  chart:
    spec:
      chart: app-template
      version: 3.5.1
      interval: 30m
      sourceRef:
        kind: HelmRepository
        name: bjw-s
        namespace: flux-system
  interval: 30m
  values:
    controllers:
      kometa-image-maid:
        type: cronjob
        annotations:
          reloader.stakater.com/auto: "true"
        cronjob:
          schedule: "30 8 * * 6"
        pod:
          affinity:
            podAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                - labelSelector:
                    matchExpressions:
                      - key: app.kubernetes.io/name
                        operator: In
                        values:
                          - plex
                  topologyKey: kubernetes.io/hostname
          securityContext:
            runAsUser: 568
            runAsGroup: 568
            runAsNonRoot: true

        containers:
          app:
            image:
              repository: docker.io/kometateam/imagemaid
              tag: v1.1.1
            env:
              PLEX_URL: http://plex.default.svc.cluster.local:32400
              PLEX_TOKEN:
                valueFrom:
                  secretKeyRef:
                    name: kometa-image-maid-secret
                    key: PLEX_TOKEN
              PLEX_PATH: /data/plex_config/Library/Application Support/Plex Media Server
              MODE: remove
              PHOTO_TRANSCODER: true
            probes:
              liveness:
                enabled: false
              readiness:
                enabled: false
              startup:
                enabled: false
            resources:
              requests:
                cpu: 25m
                memory: 128Mi
            securityContext:
              allowPrivilegeEscalation: false
              readOnlyRootFilesystem: true
              capabilities:
                drop:
                  - ALL

    persistence:
      config:
        type: emptyDir
        advancedMounts:
          kometa-image-maid:
            app:
              - path: /config
      plex-config:
        existingClaim: plex
        advancedMounts:
          kometa-image-maid:
            app:
              - path: /data/plex_config/Library/Application Support/Plex Media Server/
      plex-cache:
        existingClaim: plex-cache
        advancedMounts:
          kometa-image-maid:
            app:
              - path: /data/plex_config/Library/Application Support/Plex Media Server/Cache