---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: '{{ azure_billing_cronjob_name }}'
  namespace: '{{ ansible_operator_meta.namespace }}'
spec:
  schedule: "0 */4 * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            aadpodidbinding: '{{ pod_identity_binding_label }}'
        spec:
{% if image_pull_secret %}
          imagePullSecrets:
            - name: {{ image_pull_secret }}
{% endif %}
          initContainers:
            - name: aap-azure-billing-db
              image: '{{ azure_billing_image }}'
              imagePullPolicy: Always
              command:
                - /usr/bin/aap-azure-billing-manage
                - migrate
              volumeMounts:
                - name: "{{ ansible_operator_meta.name }}-settings"
                  mountPath: "/etc/billing/billingconf.py"
                  subPath: billingconf.py
                  readOnly: true
          containers:
            - name: aap-azure-billing
              image: '{{ azure_billing_image }}'
              imagePullPolicy: Always
              command:
                - /usr/bin/aap-azure-billing
                - -d
              volumeMounts:
                - name: "{{ ansible_operator_meta.name }}-settings"
                  mountPath: "/etc/billing/billingconf.py"
                  subPath: billingconf.py
                  readOnly: true
          volumes:
            - name: "{{ ansible_operator_meta.name }}-settings"
              secret:
                secretName: '{{ ansible_operator_meta.name }}-settings'
          restartPolicy: Never
