# Copyright 2021 Google LLC
#
# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: uptime-stats
  namespace: buildkite
spec:
  schedule: "20 * * * *"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 24
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: collect-buildkite-stats
            image: gcr.io/llvm-premerge-checks/stats:latest
            args: ["/root/llvm-premerge-checks/scripts/metrics/connect_db.sh python3 server_monitoring.py"]
            env:
            - name: BUILDKITE_AGENT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: buildkite-agent-token
                  key: token
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: CONDUIT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: conduit-api-token
                  key: token
            - name: BUILDKITE_API_TOKEN
              valueFrom:
                secretKeyRef:
                  name: buildkite-api-token
                  key: token
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: db-stats
                  key: password
            - name: SCRIPTS_REFSPEC
              value: "main"
          restartPolicy: Never
          nodeSelector:
            cloud.google.com/gke-nodepool: service