# services/logging/opensearch-prune-cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: opensearch-prune
  namespace: logging
spec:
  schedule: "23 3 * * *"
  suspend: true
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      backoffLimit: 2
      template:
        spec:
          restartPolicy: OnFailure
          nodeSelector:
            node-role.kubernetes.io/worker: "true"
            hardware: rpi5
          affinity:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                  - matchExpressions:
                      - key: hardware
                        operator: In
                        values:
                          - rpi5
          containers:
            - name: prune
              image: python:3.11-alpine
              command: ["python", "/scripts/prune.py"]
              env:
                - name: OPENSEARCH_URL
                  value: http://opensearch-master.logging.svc.cluster.local:9200
                - name: LOG_LIMIT_BYTES
                  value: "1099511627776"
                - name: LOG_INDEX_PATTERNS
                  value: "kube-*,journald-*,trace-analytics-*"
              volumeMounts:
                - name: scripts
                  mountPath: /scripts
          volumes:
            - name: scripts
              configMap:
                name: opensearch-prune-script
