---
- name: Setup OperatorHub dependencies
  k8s:
    definition:
      apiVersion: config.openshift.io/v1
      kind: OperatorHub
      metadata:
        name: cluster
      spec:
        disableAllDefaultSources: true
        sources:
        - disabled: false
          name: certified-operators
        - disabled: false
          name: redhat-operators

- name: Create OperatorGroup
  k8s:
    definition:
      apiVersion: operators.coreos.com/v1
      kind: OperatorGroup
      metadata:
        name: service-telemetry-operator-group
        namespace: "{{ namespace }}"
      spec:
        targetNamespaces:
        - "{{ namespace }}"

- name: Subscribe to AMQ Certificate Manager Operator
  k8s:
    definition:
      apiVersion: operators.coreos.com/v1alpha1
      kind: Subscription
      metadata:
        name: amq7-cert-manager-operator
        namespace: openshift-operators
      spec:
        channel: 1.x
        installPlanApproval: Automatic
        name: amq7-cert-manager-operator
        source: redhat-operators
        sourceNamespace: openshift-marketplace

- name: Enable OperatorHub.io for Elastic Cloud on Kubernetes
  k8s:
    definition:
      apiVersion: operators.coreos.com/v1alpha1
      kind: CatalogSource
      metadata:
        name: operatorhubio-operators
        namespace: openshift-marketplace
      spec:
        sourceType: grpc
        image: quay.io/operatorhubio/catalog:latest
        displayName: OperatorHub.io Operators
        publisher: OperatorHub.io
  when:
    - __service_telemetry_observability_strategy == "use_community"

- name: Subscribe to Elastic Cloud on Kubernetes Operator
  k8s:
    definition:
      apiVersion: operators.coreos.com/v1alpha1
      kind: Subscription
      metadata:
        name: elasticsearch-eck-operator-certified
        namespace: "{{ namespace }}"
      spec:
        channel: stable
        installPlanApproval: Automatic
        name: elasticsearch-eck-operator-certified
        source: certified-operators
        sourceNamespace: openshift-marketplace
  when:
    - __service_telemetry_observability_strategy == "use_community"

- name: Subscribe to AMQ Interconnect Operator
  k8s:
    definition:
      apiVersion: operators.coreos.com/v1alpha1
      kind: Subscription
      metadata:
        name: amq7-interconnect-operator
        namespace: "{{ namespace }}"
      spec:
        channel: 1.10.x
        installPlanApproval: Automatic
        name: amq7-interconnect-operator
        source: redhat-operators
        sourceNamespace: openshift-marketplace

- name: Subscribe to Prometheus Operator
  k8s:
    definition:
      apiVersion: operators.coreos.com/v1alpha1
      kind: Subscription
      metadata:
        name: prometheus
        namespace: "{{ namespace }}"
      spec:
        channel: beta
        installPlanApproval: Automatic
        name: prometheus
        source: operatorhubio-operators
        sourceNamespace: openshift-marketplace
  when:
    - __service_telemetry_observability_strategy == "use_community"
