# Copyright 2021 The Telemetry 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: job
  namespace: system
spec:
  schedule: "0 * * * *"
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            control-plane: telemetry
        spec:
          serviceAccountName: agent-sa
          initContainers:
            - name: kubernetes-agent
              image: quay.io/kubermatic/telemetry-kubernetes-agent:v0.1.0
              args:
                - "--record-dir=$(RECORD_DIR)"
              env:
                - name: RECORD_DIR
                  value: "/records"
              volumeMounts:
                - name: records
                  mountPath: "/records"
              resources:
                limits:
                  cpu: "1"
                  memory: 100Mi
                requests:
                  cpu: "0.5"
                  memory: 100Mi
            - name: kubermatic-agent
              image: quay.io/kubermatic/telemetry-kubermatic-agent:v0.1.0
              args:
                - "--record-dir=$(RECORD_DIR)"
              env:
                - name: RECORD_DIR
                  value: "/records"
              volumeMounts:
                - name: records
                  mountPath: "/records"
              resources:
                limits:
                  cpu: "1"
                  memory: 100Mi
                requests:
                  cpu: "0.5"
                  memory: 100Mi
          containers:
            - name: reporter
              image: quay.io/kubermatic/telemetry-reporter:v0.1.0
              args:
                - "http"
                - "--client-uuid=$(CLIENT_UUID)"
                - "--url=$(URL)"
                - "--record-dir=$(RECORD_DIR)"
              env:
                - name: RECORD_DIR
                  value: "/records"
                - name: URL
                  value: <URL_PLACEHOLDER>
                - name: CLIENT_UUID
                  valueFrom:
                    secretKeyRef:
                      name: client-uuid
                      key: uuid
              volumeMounts:
                - mountPath: "/records"
                  name: records
              resources:
                limits:
                  cpu: "1"
                  memory: 100Mi
                requests:
                  cpu: "0.5"
                  memory: 100Mi
          volumes:
            - name: records
              emptyDir: {}
          restartPolicy: OnFailure
