apiVersion: batch/v1
kind: CronJob
metadata:
  name: tc-collector
  labels:
    {{- include "common.labels" . | nindent 4 }}
spec:
  schedule: "*/20 * * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      backoffLimit: 0
      template:
        metadata:
          labels:
            {{- include "common.selectorLabels" . | nindent 12 }}
        spec:
          securityContext:
            runAsNonRoot: true
          restartPolicy: Never
          # 12 hours
          activeDeadlineSeconds: 43200
          containers:
            - name: tc-collector
              image: {{ .Values.images.collector }}
              resources:
                requests:
                  cpu: "3"
                  memory: 2Gi
                limits:
                  cpu: "4"
                  memory: 16Gi
              env:
                - name: TC_TOKEN
                  valueFrom:
                    secretKeyRef:
                      name: ij-perf-data-tc
                      key: token
                # memory limit — do not overload server
                - name: INSERT_WORKER_COUNT
                  value: "2"
                - name: NATS
                  value: "nats:4222"
                - name: CLICKHOUSE
                  value: "clickhouse:9000"
                - name: DATABASE_URL
                  value: {{ .Values.postgres.db_url | quote }}
                - name: GOMEMLIMIT
                  value: "1000MiB"
              volumeMounts:
                - mountPath: /etc/config
                  name: config
          imagePullSecrets:
            - name: ghcr
          volumes:
            - name: config
              configMap:
                name: tc-collector-config-{{ .Values.collector | toYaml | sha256sum }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: tc-collector-config-{{ .Values.collector | toYaml | sha256sum }}
data:
  config.json: {{ .Values.collector | toJson | quote }}