apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: api-clean
  namespace: production
spec:
  schedule: "0 3 * * *" # Each day 03:00 UTC
  successfulJobsHistoryLimit: 1
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      backoffLimit: 2
      template:
        metadata:
          name: api-clean
        spec:
          restartPolicy: Never
          containers:
          - name: sync-cleaning
            image: ontola/ori_api:sync_cleaning
            command: ["bin/ori_api", "--clean-old-versions"]
            imagePullPolicy: Always
            env:
            - name: API_DIR
              value: /var/opt/ori_data/id/api/v1
            - name: KAFKA_HOSTNAME
              valueFrom:
                configMapKeyRef:
                  key: KAFKA_HOST
                  name: config
            - name: THREAD_COUNT
              value: "6"
            - name: KAFKA_ADDRESS
              valueFrom:
                configMapKeyRef:
                  key: KAFKA_ADDRESS
                  name: config
            - name: KAFKA_USERNAME
              valueFrom:
                secretKeyRef:
                  key: KAFKA_USERNAME
                  name: secrets
            - name: KAFKA_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: KAFKA_PASSWORD
                  name: secrets
            - name: REDIS_ADDRESS
              value: redis://redis:6379
            - name: BUGSNAG_KEY
              value: f74b79ff1f813488777566c864845056
            volumeMounts:
            - mountPath: /var/opt/ori_data/id
              name: api-pvc
            resources:
              requests:
                memory: 20M
                cpu: 500m
              limits:
                memory: 1G
                cpu: 800m
          volumes:
          - name: api-pvc
            persistentVolumeClaim:
              claimName: api-pvc
          affinity:
            podAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
              - labelSelector:
                  matchExpressions:
                  - key: app
                    operator: In
                    values:
                    - api-serve
                topologyKey: kubernetes.io/hostname