# Copyright 2019 The Tekton Authors
#
# 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.
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: nightly-test-trigger
spec:
  schedule: "0 0 1 * *"
  jobTemplate:
    spec:
      template:
        spec:
          volumes:
          - name: workspace
            emptyDir: {}
          containers:
          - name: trigger
            image: curlimages/curl
            command:
              - /bin/sh
            args:
              - -ce
              - |
                cat <<EOF > /workspace/post-body.json
                {
                  "trigger-template": "$TARGET_PROJECT",
                  "params": {
                    "target": {
                      "registry": "$REGISTRY",
                      "arch": "$TARGET_ARCH",
                      "kubeconfigSecret": "$KUBECONFIG_SECRET_NAME"
                    },
                    "remote": {
                       "host": "$REMOTE_HOST",
                       "port": "$REMOTE_PORT",
                       "user": "$REMOTE_USER",
                       "secret": "$REMOTE_SECRET_NAME"
                    },
                    "run": {
                      "namespace": "$NAMESPACE"
                    }
                  }
                }
                EOF
                curl -d @/workspace/post-body.json $SINK_URL
            volumeMounts:
            - mountPath: /workspace
              name: workspace
            env:
              - name: SINK_URL
                value: "sink-url"
              - name: TARGET_PROJECT
                value: "pipeline"
              - name: NAMESPACE
                value: "bastion-z"
              - name: REGISTRY
                value: "registry"
              - name: TARGET_ARCH
                value: "s390x"
              - name: KUBECONFIG_SECRET_NAME
                value: "secret"
              - name: REMOTE_SECRET_NAME
                value: "secret"
              - name: REMOTE_HOST
                value: "host"
              - name: REMOTE_PORT
                value: "22"
              - name: REMOTE_USER
                value: "user"
          restartPolicy: Never
