---

- include_tasks: update_meteringconfig_status.yml
  vars:
    current_conditions:
      type: "Running"
      status: "True"
      message: "Reconciling Metering resources"
      lastTransitionTime: "{{ now(utc=False).isoformat() + 'Z' }}"

- name: Log event for reconciling the metering resources
  k8s_event:
    state: present
    name: metering-operator-reconciling-metering
    namespace: "{{ meta.namespace }}"
    message: Reconciling metering resources
    reason: Reconciling
    type: Normal
    source:
      component: metering-ansible-operator
    involvedObject:
      apiVersion: metering.openshift.io
      kind: MeteringConfig
      name: "{{ meta.name }}"
      namespace: "{{ meta.namespace }}"

- name: Deploy metering resources
  include_tasks: deploy_resources.yml
  vars:
    values_file: /tmp/metering-values.yaml
    resources:
      - template_file: templates/metering/metering-roles.yaml
        apis: [ {kind: role, api_version: 'rbac.authorization.k8s.io/v1'} ]
        prune_label_value: openshift-metering-roles
      - template_file: templates/metering/metering-service-ca-crt.yaml
        apis: [ {kind: ConfigMap} ]
        prune_label_value: openshift-metering-service-ca-crt
      - template_file: templates/metering/metering-rolebindings.yaml
        apis: [ {kind: rolebindings, api_version: 'rbac.authorization.k8s.io/v1'} ]
        prune_label_value: openshift-metering-rolebindings
      - template_file: templates/metering/metering-root-ca-secret.yaml
        apis: [ {kind: Secret} ]
        prune_label_value: openshift-metering-root-ca-secret
        create: "{{ meteringconfig_create_metering_root_ca_secret }}"

- include_tasks: update_meteringconfig_status.yml
  vars:
    current_conditions:
      type: "Running"
      status: "True"
      message: "Finished reconciling Metering resources"
      lastTransitionTime: "{{ now(utc=False).isoformat() + 'Z' }}"
