---

- name: Validate fields when OCP-only features are disabled
  block:
  - name: Validate that top-level TLS key is unset/disabled
    assert:
      that:
        - meteringconfig_spec | json_query('tls.enabled') != true
      msg: "Invalid configuration for non-OKD distributions: You cannot set the tls.enabled key to true when disabling OCP-only features."
  - name: Validate that the Prometheus URL is set
    assert:
      that:
        - meteringconfig_spec['reporting-operator'] | json_query('spec.config.prometheus.url') != ""
      msg: "Invalid configuration for non-OKD distributions: You must set the reporting-operator.spec.config.prometheus.url."
  - name: Validate that the reporting-operator Openshift Route is not enabled
    assert:
      that:
      - meteringconfig_spec['reporting-operator'] | json_query('spec.route.enabled') != true
      msg: "Invalid configuration for non-OKD distributions: You cannot enable the Openshift-only reporting-operator route."
  - name: Validate that the reporting-operator OAuth authProxy is not enabled
    assert:
      that:
      - meteringconfig_spec['reporting-operator'] | json_query('spec.authProxy.enabled') != true
      msg: "Invalid configuration for non-OKD distributions: You cannot enable the Openshift-only reporting-operator authProxy."
  when: meteringconfig_ocp_disabled

- name: Validate storage configuration
  assert:
    that:
      - meteringconfig_spec | json_query('storage.type') == "hive"
    msg: "Unsupported spec.storage.type, only 'hive' is  a supported option"

- name: Validate Hive storage configuration
  assert:
    that:
      - hiveStorageType is not undefined and hiveStorageType in ['s3', 'sharedPVC', 'hdfs', 'azure', 'gcs' , 's3Compatible']
    msg: "Invalid spec.storage.hive.type: '{{ hiveStorageType }}', must be one of 's3', 'azure', 'gcs', 's3Compatible' or 'sharedPVC'"
  vars:
    hiveStorageType: "{{ meteringconfig_spec_overrides | json_query('storage.hive.type') }}"
