apiVersion: batch/v1
kind: CronJob
metadata:
  name: sync
spec:
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 1
  concurrencyPolicy: Forbid
  activeDeadlineSeconds: 900
  startingDeadlineSeconds: 180
  schedule: "*/30 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: Never
          startingDeadlineSeconds: 600
          containers:
          - name: blockerbugs-sync
            image: image-registry.openshift-image-registry.svc:5000/blockerbugs/blockerbugs:latest
            env:
{% if env == 'staging' %}
            - name: POSTGRESQL_USER
              value: "{{ stg_blockerbugs_db_user }}"
{% else %}
            - name: POSTGRESQL_USER
              value: "{{ prod_blockerbugs_db_user }}"
{% endif %}
            - name: POSTGRESQL_DATABASE
              value: "blockerbugs"
            - name: POSTGRESQL_SERVICE_HOST
              value: "db01{{ env_suffix }}.iad2.fedoraproject.org"
            - name: POSTGRESQL_SERVICE_PORT
              value: "5432"
{% if env == 'staging' %}
            - name: POSTGRESQL_PASSWORD
              value: "{{ stg_blockerbugs_db_password }}"
            - name: SECRET_KEY
              value: "{{ stg_blockerbugs_secret_key }}"
            - name: PAGURE_REPO_TOKEN
              value: "{{ stg_blockerbugs_pagure_repo_token_secret }}"
            - name: PAGURE_REPO_WEBHOOK_KEY
              value: "{{ stg_blockerbugs_pagure_repo_webhook_key_secret }}"
            - name: BUGZILLA_API_KEY
              value: "{{ stg_blockerbugs_bz_api_key }}"
            - name: PAGURE_URL
              value: "https://stg.pagure.io/"
            - name: PAGURE_API
              value: "https://stg.pagure.io/api/0/"
            - name: BUGZILLA_URL
              value: "https://bugzilla.stage.redhat.com"
{% else %}
            - name: POSTGRESQL_PASSWORD
              value: "{{ prod_blockerbugs_db_password }}"
            - name: SECRET_KEY
              value: "{{ prod_blockerbugs_secret_key }}"
            - name: PAGURE_REPO_TOKEN
              value: "{{ prod_blockerbugs_pagure_repo_token_secret }}"
            - name: PAGURE_REPO_WEBHOOK_KEY
              value: "{{ prod_blockerbugs_pagure_repo_webhook_key_secret }}"
            - name: BUGZILLA_API_KEY
              value: "{{ prod_blockerbugs_bz_api_key }}"
            - name: PAGURE_URL
              value: "https://pagure.io/"
            - name: PAGURE_API
              value: "https://pagure.io/api/0/"
            - name: BUGZILLA_URL
              value: "https://bugzilla.redhat.com"
{% endif %}
            - name: BLOCKERBUGS_URL
              value: "https://qa{{ env_suffix }}.fedoraproject.org/blockerbugs/"
            - name: BLOCKERBUGS_API
              value: "https://qa{{ env_suffix }}.fedoraproject.org/blockerbugs/api/v0/"
            - name: FAS_BASE_URL
              value: "https://admin{{ env_suffix }}.fedoraproject.org/accounts/"
            - name: FAS_ADMIN_GROUP
              value: "qa-admin"
            - name: PAGURE_BOT_USERNAME
              value: "blockerbot"
            - name: PAGURE_BOT_ENABLED
              value: "True"
            - name: PAGURE_REPO
              value: "fedora-qa/blocker-review"
            - name: BODHI_URL
              value: "https://bodhi{{ env_suffix }}.fedoraproject.org/"
            - name: OPENSHIFT_PROD
{% if env == 'staging' %}
              value: "0"
{% else %}
              value: "1"
{% endif %}
            - name: blockerbugs-secret-volume
              mountPath: /opt/app-root/secret/
              readOnly: true
            command: ["python", "/opt/app-root/src/blockerbugs/cli.py", "sync"]
          volumes:
          - name: blockerbugs-secret-volume
            secret:
              secretName: blockerbugs-secret