# Copyright 2019 The Knative 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: broker-imc-sender-receiver
  namespace: default
spec:
  schedule: "0/15 * * * *"
  # History must be zero to ensure no failed pods stick around and block the next job
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 0
  jobTemplate:
    spec:
      completions: 1
      parallelism: 1
      backoffLimit: 0
      # Allow up to 14 minutes, then clean up to make room for the next attempt
      activeDeadlineSeconds: 840
      template:
        metadata:
          labels:
            role: broker-imc-receiver
        spec:
          serviceAccountName: perf-eventing
          restartPolicy: Never
          containers:
            - name: sender
              image: knative.dev/eventing/test/test_images/performance
              args:
                - "--roles=sender"
                - "--sink=http://imc-broker.default.svc.cluster.local"
                - "--aggregator=broker-imc-aggregator:10000"
                - "--pace=100:10,400:20,800:30,900:60,1000:60,1100:60,1200:60"
              env:
                - name: POD_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.name
                - name: POD_NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
              resources:
                requests:
                  cpu: 1200m
                  memory: 3Gi
            - name: receiver
              image: knative.dev/eventing/test/test_images/performance
              args:
                - "--roles=receiver"
                - "--aggregator=broker-imc-aggregator:10000"
                - "--pace=100:10,400:20,800:30,900:60,1000:60,1100:60,1200:60"
              env:
                - name: POD_NAME
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.name
                - name: POD_NAMESPACE
                  valueFrom:
                    fieldRef:
                      fieldPath: metadata.namespace
              resources:
                requests:
                  cpu: 1200m
                  memory: 3Gi
              ports:
                - name: cloudevents
                  containerPort: 8080

---

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: broker-imc-aggregator
  namespace: default
spec:
  schedule: "0/15 * * * *"
  # History must be zero to ensure no failed pods stick around and block the next job
  successfulJobsHistoryLimit: 0
  failedJobsHistoryLimit: 0
  jobTemplate:
    spec:
      completions: 1
      parallelism: 1
      backoffLimit: 0
      # Allow up to 14 minutes, then clean up to make room for the next attempt
      activeDeadlineSeconds: 840
      template:
        metadata:
          labels:
            role: broker-imc-aggregator
        spec:
          serviceAccountName: perf-eventing
          restartPolicy: Never
          containers:
            - name: aggregator
              image: knative.dev/eventing/test/test_images/performance
              args:
                - "--roles=aggregator"
                # set to the number of sender + receiver (same image that does both counts 2)
                - "--expect-records=2"
                - "--mako-tags=channel=imc"
              ports:
                - name: grpc
                  containerPort: 10000
              resources:
                requests:
                  cpu: 1000m
                  memory: 2Gi
              volumeMounts:
                - name: config-mako
                  mountPath: /etc/config-mako
                - name: mako-secrets
                  mountPath: /var/secret
              terminationMessagePolicy: FallbackToLogsOnError
            - name: mako
              image: gcr.io/knative-performance/mako-microservice:latest
              env:
                - name: GOOGLE_APPLICATION_CREDENTIALS
                  value: /var/secret/robot.json
              volumeMounts:
                - name: mako-secrets
                  mountPath: /var/secret
              ports:
                - name: quickstore
                  containerPort: 9813
              terminationMessagePolicy: FallbackToLogsOnError
          volumes:
            - name: config-mako
              configMap:
                name: config-mako
            - name: mako-secrets
              secret:
                secretName: mako-secrets
