---
kind: Deployment
apiVersion: apps/v1
metadata:
  namespace: media
  name: cloudplow-uploader
  annotations:
    fluxcd.io/ignore: "false"
    fluxcd.io/automated: "false"
  labels:
    app: cloudplow-uploader
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cloudplow-uploader
  template:
    metadata:
      labels:
        app: cloudplow-uploader
    spec:
      # dnsPolicy: None
      # dnsConfig:
      #   nameservers:
      #   - "${LB_BLOCKY_IP}"
      initContainers:
      - name: git-config
        image: alpine/git:v2.32.0
        env:
        - name: GITEA_TOKEN
          value: "${SECRET_GITEA_ACCESS_TOKEN}"
        - name: URL
          value: "git.dev.${SECRET_DOMAIN}"
        command:
        - "/bin/sh"
        - "-c"
        - |
          set -o nounset
          set -o errexit
          # sleep 600000000m
          if [ -z "${SECRET_GITEA_ACCESS_TOKEN}" ]; then
            printf "%s - Error - Missing GITEA_TOKEN environment variable" "$(date -u)"
            exit 1
          fi
          git clone --depth 1 "https://${SECRET_GITEA_ACCESS_TOKEN}@git.dev.${SECRET_DOMAIN}/dcplaya/Configs.git" /shared/Configs
          chown -R 1000:1000 /shared/Configs
          exit 0
        volumeMounts:
        - name: shared
          # Path will be /shared/Configs/RClone/default.conf
          mountPath: /shared
      containers:
      - name: cloudplow-uploader
        image: sabrsorensen/alpine-cloudplow:latest
        imagePullPolicy: Always
        env:
        - name: PUID
          value: "1000"
        - name: GUID
          value: "1000"
        - name: CLOUDPLOW_CONFIG
          value: "/shared/Configs/Cloudplow/config.json"
        - name: CLOUDPLOW_LOGFILE
          value: "/dev/null"
        - name: CLOUDPLOW_LOGLEVEL
          value: "INFO"
        - name: CLOUDPLOW_CACHEFILE
          value: "/volume1/Media/config/cloudplow/cache.db"
        - name: TZ
          value: "America/Los_Angeles"
        volumeMounts:
        - mountPath: /volume1/Media
          name: media-pvc
        - mountPath: /shared
          name: shared
        resources:
          requests:
            memory: 500Mi
            cpu: 1000m
          limits:
            memory: 2000Mi
            cpu: 1000m
      volumes:
      - name: media-pvc
        persistentVolumeClaim:
          claimName: nfs-nas-media-pvc
      - name: shared
        emptyDir: {}
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/hostname
                operator: NotIn
                values:
                - node04
