apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: photoprism-index
  namespace: media
spec:
  schedule: "0 * * * *"
  concurrencyPolicy: Forbid
  failedJobsHistoryLimit: 1
  jobTemplate:
    spec:
      parallelism: 1
      template:
        spec:
          restartPolicy: OnFailure
          volumes:
            - name: config
              persistentVolumeClaim:
                claimName: photoprism-config
            - name: originals
              nfs:
                server: ${NFS_SERVER_2}
                path: /share/images

          securityContext:
            fsGroup: 1000
            runAsGroup: 1000
            runAsUser: 1000

          containers:
            - name: photoprism-index
              image: photoprism/photoprism:20220107
              imagePullPolicy: IfNotPresent
              args:
                - /photoprism/bin/photoprism
                - index
              volumeMounts:
                - name: config
                  mountPath: /photoprism/storage
                - name: originals
                  mountPath: /photoprism/originals
              resources:
                requests:
                  memory: "1Gi"
                  cpu: "1"
                limits:
                  memory: "2Gi"
                  cpu: "1"

          affinity:
            podAntiAffinity:
              preferredDuringSchedulingIgnoredDuringExecution:
                - weight: 100
                  podAffinityTerm:
                    labelSelector:
                      matchExpressions:
                        - key: app.kubernetes.io/name
                          operator: In
                          values:
                            - prometheus
                    topologyKey: kubernetes.io/hostname
