apiVersion: batch/v1
kind: Job
metadata:
  name: ${FQDN}-sync-buckets
  namespace: ${DOMAIN}
spec:
  template:
    spec:
      containers:
      - command: [/sync/sync.sh]
        env:
        - name: RO_OBJECTSTORE_S3_KEY
          valueFrom:
            secretKeyRef:
              key: AWS_ACCESS_KEY_ID 
              name: ${FQDN}-s3-ro
        - name: RO_OBJECTSTORE_S3_SECRET 
          valueFrom:
            secretKeyRef:
              key: AWS_SECRET_ACCESS_KEY
              name: ${FQDN}-s3-ro
        - name: NEW_OBJECTSTORE_S3_KEY
          valueFrom:
            secretKeyRef:
              key: AWS_ACCESS_KEY_ID 
              name: ${FQDN}-s3-new
        - name: NEW_OBJECTSTORE_S3_SECRET 
          valueFrom:
            secretKeyRef:
              key: AWS_SECRET_ACCESS_KEY
              name: ${FQDN}-s3-new
        image: libresh/nextcloud:${NC_IMAGE_TAG}
        imagePullPolicy: IfNotPresent
        name: sync-buckets
        volumeMounts:
        - name: sync-script
          mountPath: /sync/
      volumes:
      - name: sync-script
        configMap:
          name: sync-script
          defaultMode: 0700
      restartPolicy: Never
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: sync-script
data:
  sync.sh: |
    #!/bin/bash -eux
    export MC_HOST_ro=https://${RO_AWS_ACCESS_KEY_ID}:${RO_AWS_SECRET_ACCESS_KEY}@s3.standard.indie.host
    export MC_HOST_new=https://${NEW_AWS_ACCESS_KEY_ID}:${NEW_AWS_SECRET_ACCESS_KEY}@hot-objects.liiib.re
    mc mirror --overwrite ro/${FQDN} new/${FQDN}
