# services/monitoring/availability-rollup-cronjob.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: atlas-availability-request-v4-rollup-initial
  namespace: monitoring
spec:
  activeDeadlineSeconds: 900
  backoffLimit: 2
  template:
    metadata:
      labels:
        app: atlas-availability-request-v4-rollup
    spec:
      restartPolicy: Never
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/hostname
                    operator: NotIn
                    values:
                      - titan-22
                      - titan-24
      containers:
        - name: rollup
          image: python:3.12-alpine
          command: ["python", "/scripts/availability_rollup.py"]
          env:
            - name: VM_URL
              value: http://victoria-metrics-single-server:8428
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              cpu: 500m
              memory: 256Mi
          volumeMounts:
            - name: script
              mountPath: /scripts
              readOnly: true
      volumes:
        - name: script
          configMap:
            name: atlas-availability-rollup-script

---

apiVersion: batch/v1
kind: CronJob
metadata:
  name: atlas-availability-request-v4-rollup
  namespace: monitoring
spec:
  schedule: "10 0 * * *"
  timeZone: Etc/UTC
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      activeDeadlineSeconds: 900
      backoffLimit: 2
      template:
        metadata:
          labels:
            app: atlas-availability-request-v4-rollup
        spec:
          restartPolicy: Never
          affinity:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                  - matchExpressions:
                      - key: kubernetes.io/hostname
                        operator: NotIn
                        values:
                          - titan-22
                          - titan-24
          containers:
            - name: rollup
              image: python:3.12-alpine
              command: ["python", "/scripts/availability_rollup.py"]
              env:
                - name: VM_URL
                  value: http://victoria-metrics-single-server:8428
              resources:
                requests:
                  cpu: 50m
                  memory: 64Mi
                limits:
                  cpu: 500m
                  memory: 256Mi
              volumeMounts:
                - name: script
                  mountPath: /scripts
                  readOnly: true
          volumes:
            - name: script
              configMap:
                name: atlas-availability-rollup-script
