apiVersion: v1
kind: Pod
metadata:
  name: apps-migration
  namespace: nextcloud
spec:
  volumes:
    - name: old-apps
      persistentVolumeClaim:
        claimName: nextcloud-apps-pvc
    - name: new-apps
      persistentVolumeClaim:
        claimName: nextcloud-apps-pvc-longhorn
  containers:
    - name: migrator
      image: alpine:3.18
      volumeMounts:
        - name: old-apps
          mountPath: /old
        - name: new-apps
          mountPath: /new
      command: ['sh']
      args:
        - -c
        - |
          echo "Copying apps data..."
          if [ "$(ls -A /old)" ]; then
            cp -rv /old/* /new/ 2>/dev/null || true
            echo "Apps migration completed"
          else
            echo "Old apps is empty"
          fi
          sleep infinity
  restartPolicy: Never
