apiVersion: batch/v1
kind: CronJob
metadata:
  name: mysql-o11y
spec:
  schedule: "*/1 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: mysql
            image: mysql:8.0
            command: ["/bin/bash", "-c"]
            args:
            - |
              mysqldump --single-transaction \
              --quick \
              --set-charset \
              --no-tablespaces \
              --set-gtid-purged=OFF \
              -u $RDS_USER -p"$RDS_PASSWORD" -h $RDS_HOST dreamkast \
              conference_days conferences proposal_item_configs proposal_items \
              proposals talk_categories talk_difficulties talk_times talks talks_speakers \
              tracks stats_of_registrants viewer_counts \
              > $HOME/rds.dump; \
              mysql -u $MYSQL_USER -p"$MYSQL_PASSWORD" -h $MYSQL_HOST dreamkast < $HOME/rds.dump
            env:
            - name: RDS_HOST
              value: dreamkast-prd-rds.c6eparu1hmbv.ap-northeast-1.rds.amazonaws.com
            - name: RDS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: rds-secret
                  key: password
            - name: RDS_USER
              valueFrom:
                secretKeyRef:
                  name: rds-secret
                  key: username
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: password
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: username
            - name: MYSQL_HOST
              value: mysql-o11y
          restartPolicy: OnFailure
