# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# 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.

# Start a large scale download using Kubernetes and the Cloud C++ GCS Library.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: storage-throughput-vs-cpu
  labels:
    app: storage-throughput-vs-cpu
spec:
  schedule: "* */1 * * *" # hourly
  # Only count the failures in the last 60 seconds towards the
  # "FailedNeedsStart" limit, and allow the job to start even if it missed the
  # start time in the last 60 seconds.
  #    https://stackoverflow.com/questions/51065538
  startingDeadlineSeconds: 60
  concurrencyPolicy: "Forbid"
  jobTemplate:
    spec:
      parallelism: 25
      completions: 25
      template:
        spec:
          restartPolicy: OnFailure
          volumes:
            - name: service-account-key
              secret:
                secretName: service-account-key
          containers:
            - name: storage-throughput-vs-cpu
              image: gcr.io/@PROJECT_ID@/google-cloud-cpp-benchmarks:latest
              imagePullPolicy: Always
              args: [
                  '/r/storage_throughput_vs_cpu_benchmark',
                  '--project-id=@PROJECT_ID@',
                  '--region=@REGION@',
                  '--duration=5m',
                  '--minimum-sample-count=400',
                  '--maximum-object-size=512MiB',
                  '--minimum-chunk-size=16MiB',
                  '--maximum-chunk-size=32MiB'
              ]
              volumeMounts:
                - name: service-account-key
                  mountPath: /var/secrets/service-account-key
              env:
                - name: GOOGLE_APPLICATION_CREDENTIALS
                  value: /var/secrets/service-account-key/key.json
