---
- name: Set default InfraWatch OperatorSource manifest
  set_fact:
    infrawatch_catalog_source_manifest: |
      apiVersion: operators.coreos.com/v1alpha1
      kind: CatalogSource
      metadata:
        name: infrawatch-operators
        namespace: openshift-marketplace
      spec:
        displayName: InfraWatch Operators
        image: quay.io/infrawatch-operators/infrawatch-catalog:unstable
        publisher: InfraWatch
        sourceType: grpc
        updateStrategy:
          registryPoll:
            interval: 30m
  when: infrawatch_catalog_source_manifest is not defined

- name: Set default Smart Gateway Operator Subscription manifest
  set_fact:
    smart_gateway_operator_subscription_manifest: |
      apiVersion: operators.coreos.com/v1alpha1
      kind: Subscription
      metadata:
        name: smart-gateway-operator
        namespace: "{{ namespace }}"
      spec:
        channel: unstable
        installPlanApproval: Automatic
        name: smart-gateway-operator
        source: infrawatch-operators
        sourceNamespace: openshift-marketplace
  when: smart_gateway_operator_subscription_manifest is not defined

- name: Set default Service Telemetry Operator Subscription manifest
  set_fact:
    service_telemetry_operator_subscription_manifest: |
      apiVersion: operators.coreos.com/v1alpha1
      kind: Subscription
      metadata:
        name: service-telemetry-operator
        namespace: "{{ namespace }}"
      spec:
        channel: unstable
        installPlanApproval: Automatic
        name: service-telemetry-operator
        source: infrawatch-operators
        sourceNamespace: openshift-marketplace
  when: service_telemetry_operator_subscription_manifest is not defined

- name: Subscribe to Smart Gateway Operator
  k8s:
    definition:
      '{{ smart_gateway_operator_subscription_manifest }}'

- name: Subscribe to Service Telemetry Operator
  k8s:
    definition:
      '{{ service_telemetry_operator_subscription_manifest }}'

- name: Enable InfraWatch Catalog Source
  k8s:
    definition:
      '{{ infrawatch_catalog_source_manifest }}'
