apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: weekreport
spec:
  schedule: "0 0 * * 0"  # At 00:00 on Sunday
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: dayreport
            image: docker.io/library/postgres:13.0
            imagePullPolicy: IfNotPresent
            envFrom:
              - secretRef:
                  name: backup-credentials
              - configMapRef:
                  name: backup-config
            command:
              - sh
              - -c
              - psql -d "postgresql://$DATABASE_USER:$DATABASE_PASSWORD@$DATABASE_HOST_NAME:$PORT_NUMBER/$DATABASE_NAME" -c "SELECT generate_report('week');"
          restartPolicy: OnFailure
