---
- command: >
    {{openshift.common.client_binary}}
    --config={{mktemp.stdout}}/admin.kubeconfig
    get rc
    -l metrics-infra=heapster
    -o name
    -n {{openshift_metrics_project}}
  register: metrics_heapster_rc
  changed_when: "'No resources found' not in metrics_heapster_rc.stderr"
  check_mode: no

- name: Stop Heapster
  oc_scale:
    kind: rc
    name: "{{object.split('/')[1]}}"
    kubeconfig: "{{mktemp.stdout}}/admin.kubeconfig"
    namespace: "{{openshift_metrics_project}}"
    replicas: 0
  with_items: "{{metrics_heapster_rc.stdout_lines}}"
  loop_control:
    loop_var: object

- command: >
    {{openshift.common.client_binary}}
    --config={{mktemp.stdout}}/admin.kubeconfig
    get rc
    -l metrics-infra=hawkular-metrics
    -o name
    -n {{openshift_metrics_project}}
  register: metrics_hawkular_rc
  changed_when: "'No resources found' not in metrics_hawkular_rc.stderr"

- name: Stop Hawkular Metrics
  oc_scale:
    kind: rc
    name: "{{object.split('/')[1]}}"
    kubeconfig: "{{mktemp.stdout}}/admin.kubeconfig"
    namespace: "{{openshift_metrics_project}}"
    replicas: 0
  with_items: "{{metrics_hawkular_rc.stdout_lines}}"
  loop_control:
    loop_var: object
  changed_when: metrics_hawkular_rc | length > 0

- command: >
    {{openshift.common.client_binary}} --config={{mktemp.stdout}}/admin.kubeconfig
    get rc
    -o name
    -l metrics-infra=hawkular-cassandra
    -n {{openshift_metrics_project}}
  register: metrics_cassandra_rc
  changed_when: "'No resources found' not in metrics_cassandra_rc.stderr"

- name: Stop Hawkular Cassandra
  oc_scale:
    kind: rc
    name: "{{object.split('/')[1]}}"
    kubeconfig: "{{mktemp.stdout}}/admin.kubeconfig"
    namespace: "{{openshift_metrics_project}}"
    replicas: 0
  with_items: "{{metrics_cassandra_rc.stdout_lines}}"
  loop_control:
    loop_var: object
  when: metrics_cassandra_rc is defined
  changed_when: metrics_cassandra_rc | length > 0
