# Copyright 2020 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
#
#     https://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.

"apiVersion": "batch/v1beta1"
"kind": "CronJob"
"metadata":
  "name": "tf-nightly-keras-api-rnn-v2-32"
  "namespace": "automated"
"spec":
  "concurrencyPolicy": "Forbid"
  "jobTemplate":
    "spec":
      "activeDeadlineSeconds": 3600
      "backoffLimit": 1
      "template":
        "metadata":
          "annotations":
            "tf-version.cloud-tpus.google.com": "nightly"
        "spec":
          "containers":
          - "env":
            - "name": "POD_NAME"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.name"
            - "name": "POD_NAMESPACE"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.namespace"
            "image": "gcr.io/xl-ml-test/health-monitor:stable"
            "imagePullPolicy": "Always"
            "name": "monitor"
          - "args":
            - "/bin/bash"
            - "-c"
            - |
              set -u
              set -e
              set -x
              
              export PATH=$PATH:/root/google-cloud-sdk/bin
              gcloud source repos clone tf2-api-tests --project=xl-ml-test
              cd tf2-api-tests
              pip3 install behave
              behave -e ipynb_checkpoints --tags=-fails --tags=-failspod -i rnn
              
            "env":
            - "name": "POD_NAME"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.name"
            - "name": "POD_UID"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.uid"
            - "name": "POD_NAMESPACE"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.namespace"
            - "name": "JOB_NAME"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.labels['job-name']"
            - "name": "MODEL_DIR"
              "value": "$(OUTPUT_BUCKET)/tf-nightly/keras-api/rnn/v2-32/$(JOB_NAME)"
            "envFrom":
            - "configMapRef":
                "name": "gcs-buckets"
            "image": "gcr.io/xl-ml-test/tensorflow:nightly"
            "imagePullPolicy": "Always"
            "name": "train"
            "resources":
              "limits":
                "cloud-tpus.google.com/preemptible-v2": 32
              "requests":
                "cpu": 2
                "memory": "20G"
            "volumeMounts":
            - "mountPath": "/dev/shm"
              "name": "dshm"
              "readOnly": false
          "initContainers":
          - "env":
            - "name": "POD_NAME"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.name"
            - "name": "POD_UID"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.uid"
            - "name": "POD_NAMESPACE"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.namespace"
            - "name": "JOB_NAME"
              "valueFrom":
                "fieldRef":
                  "fieldPath": "metadata.labels['job-name']"
            - "name": "MODEL_DIR"
              "value": "$(OUTPUT_BUCKET)/tf-nightly/keras-api/rnn/v2-32/$(JOB_NAME)"
            - "name": "METRIC_CONFIG"
              "value": |
                {
                 "metric_collection_config": {
                  "default_aggregation_strategies": [
                   "final"
                  ],
                  "metric_to_aggregation_strategies": {
                   "examples_per_second": [
                    "average"
                   ]
                  },
                  "use_run_name_prefix": true,
                  "write_to_bigquery": true
                 },
                 "regression_test_config": {
                  "alert_for_failed_jobs": true
                 },
                 "test_name": "tf-nightly-keras-api-rnn-v2-32"
                }
            "envFrom":
            - "configMapRef":
                "name": "gcs-buckets"
            "image": "gcr.io/xl-ml-test/publisher:stable"
            "imagePullPolicy": "Always"
            "name": "publisher"
          "nodeSelector":
            "tpu-available": "true"
          "restartPolicy": "Never"
          "volumes":
          - "emptyDir":
              "medium": "Memory"
            "name": "dshm"
  "schedule": "0 10 * * *"
  "successfulJobsHistoryLimit": 1