apiVersion: batch/v1
kind: CronJob
metadata:
  name: metrics-status-collector
  namespace: observability
spec:
  schedule: "0 18 * * *"
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 1
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      activeDeadlineSeconds: 64800
      backoffLimit: 1
      template:
        metadata:
          labels:
            azure.workload.identity/use: "true"
        spec:
          serviceAccountName: regional-server-controller-manager
          restartPolicy: Never
          nodeSelector:
            node_type: worker
          containers:
          - name: metrics-status-collector
            image: o11yprod.azurecr.io/metrics-status-collector
            command: ["/bin/sh","-c"]
            args:
              - >
                python fetch_vm_data.py
                --date $(date -u -d 'yesterday' +%Y%m%d)
                --delta-root abfs://o11y-TMPL_ENV-shared-TMPL_LOGICAL_REGION/deltalake/global/metrics-status
            env:
              - name: AZURE_STORAGE_ACCOUNT_NAME
                value: o11yTMPL_ENVTMPL_LOGICAL_REGION
              - name: STORAGE_ACCOUNT_NAME
                value: o11yTMPL_ENVTMPL_LOGICAL_REGION
            resources:
              requests:
                cpu: "300m"
                memory: "512Mi"
              limits:
                cpu: "2"
                memory: "2Gi"
            volumeMounts:
            - name: azure-identity-token
              mountPath: /var/run/secrets/azure/tokens
              readOnly: true
          volumes:
          - name: azure-identity-token
            projected:
              sources:
              - serviceAccountToken:
                  audience: api://AzureADTokenExchange
                  expirationSeconds: 3600
                  path: azure-identity-token
