---

- name: Log event for starting the reporting configuration
  k8s_event:
    state: present
    name: metering-operator-configuring-reporting
    namespace: "{{ meta.namespace }}"
    message: Configuring reporting for the metering-ansible-operator
    reason: Started
    type: Normal
    source:
      component: metering-ansible-operator
    involvedObject:
      apiVersion: metering.openshift.io
      kind: MeteringConfig
      name: "{{ meta.name }}"
      namespace: "{{ meta.namespace }}"

- name: Query Kubernetes for API version
  command: kubectl version -o json
  register: kube_version

- name: Set default ReportDataSources to use based on Kubernetes version
  block:
  - name: Log Kubernetes version
    debug:
      msg: |
        Kubernetes Minor Version: {{ kube_minor_version }}
        Kubernetes version at least 1.14: {{ kube_version_at_least_1_14 }}

  - name: Set default ReportDataSources to use based on Kubernetes version
    set_fact:
      meteringconfig_reporting_enable_post_kube_1_14_datasources: "{{ kube_version_at_least_1_14 }}"
  vars:
    kube_minor_version: "{{ (kube_version.stdout | from_json | json_query('serverVersion.minor')).rstrip('+') }}"
    kube_version_at_least_1_14: "{{ ((kube_minor_version | int) >= 14) | bool }}"
