# MIT License
#
# Copyright (c) 2018-2019 Red Hat, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: run-validation
spec:
  # runs every day at 4 a.m.
  schedule: "0 4 * * *"
  jobTemplate:
    spec:
      # https://docs.openshift.com/container-platform/3.11/dev_guide/jobs.html#jobs-setting-maximum-duration
      # set maximum duration to 4 hours
      activeDeadlineSeconds: 14400
      template:
        spec:
          volumes:
            - name: copr-config
              secret:
                secretName: copr-config
          containers:
            - name: run-validation
              image: usercont/packit-service-validation
              env:
                - name: GITHUB_TOKEN
                  valueFrom:
                    secretKeyRef:
                      name: github-token
                      key: token
                - name: SENTRY_SECRET
                  valueFrom:
                    secretKeyRef:
                      name: packit-sentry
                      key: sentry
              command: ["python3", "/usr/bin/packit-service-validation.py"]
              volumeMounts:
                - name: copr-config
                  mountPath: /.config
              resources:
                limits:
                  memory: "80Mi"
                  cpu: "100m"
          restartPolicy: OnFailure
