---
# delete the deployment objects that we had created
- name: delete logging api objects
  oc_obj:
    state: absent
    kind: "{{ item }}"
    namespace: "{{ openshift_logging_namespace }}"
    selector: "logging-infra"
  with_items:
    - dc
    - rc
    - svc
    - routes
    - templates
    - ds

# return all persistent volume claims as well if purge is set
- name: delete logging pvc objects
  oc_obj:
    state: absent
    kind: pvc
    namespace: "{{ openshift_logging_namespace }}"
    selector: "logging-infra"
  when:
    - openshift_logging_purge_logging | default(false) | bool

# delete the oauthclient
- name: delete oauthclient kibana-proxy
  oc_obj:
    state: absent
    kind: oauthclient
    namespace: "{{ openshift_logging_namespace }}"
    name: kibana-proxy

# delete any image streams that we may have created
- name: delete logging is
  oc_obj:
    state: absent
    kind: is
    namespace: "{{ openshift_logging_namespace }}"
    selector: "logging-infra=support"

# delete our old secrets
- name: delete logging secrets
  oc_secret:
    state: absent
    namespace: "{{ openshift_logging_namespace }}"
    name: "{{ item }}"
  with_items:
    - logging-fluentd
    - logging-elasticsearch
    - logging-kibana
    - logging-kibana-proxy
    - logging-curator
    - logging-mux

# delete our service accounts
- name: delete service accounts
  oc_serviceaccount:
    state: absent
    namespace: "{{ openshift_logging_namespace }}"
    name: "{{ item }}"
  with_items:
    - aggregated-logging-elasticsearch
    - aggregated-logging-kibana
    - aggregated-logging-curator
    - aggregated-logging-fluentd

# delete role bindings
- name: delete rolebindings
  oc_obj:
    state: absent
    kind: rolebinding
    namespace: "{{ openshift_logging_namespace }}"
    name: logging-elasticsearch-view-role

# delete cluster role bindings
- name: delete cluster role bindings
  oc_obj:
    state: absent
    kind: clusterrolebindings
    namespace: "{{ openshift_logging_namespace }}"
    name: rolebinding-reader

# delete cluster roles
- name: delete cluster roles
  oc_obj:
    state: absent
    kind: clusterrole
    namespace: "{{ openshift_logging_namespace }}"
    name: "{{ item }}"
  with_items:
    - rolebinding-reader
    - daemonset-admin
    - prometheus-metrics-viewer

# delete our configmaps
- name: delete configmaps
  oc_obj:
    state: absent
    kind: configmap
    namespace: "{{ openshift_logging_namespace }}"
    name: "{{ item }}"
  with_items:
    - logging-curator
    - logging-elasticsearch
    - logging-elasticsearch-ops
    - logging-fluentd
    - logging-mux

# remove annotations added by logging
- command: >
    {{ openshift_client_binary }}
    --config={{ openshift.common.config_base }}/master/admin.kubeconfig
    get namespaces -o name {{ __default_logging_ops_projects | join(' ') }}
  register: __logging_ops_projects

- name: Remove Annotation of Operations Projects
  command: >
    {{ openshift_client_binary }}
    --config={{ openshift.common.config_base }}/master/admin.kubeconfig
    annotate {{ project }} openshift.io/logging.ui.hostname-
  with_items: "{{ __logging_ops_projects.stdout_lines }}"
  loop_control:
    loop_var: project
  when:
    - __logging_ops_projects.stderr | length == 0

## EventRouter
- import_role:
    name: openshift_logging_eventrouter
  when:
    not openshift_logging_install_eventrouter | default(false) | bool

# Update console config in openshift-web-console namespace
- name: Remove Kibana route information from the web console config
  include_role:
    name: openshift_web_console
    tasks_from: update_console_config.yml
  vars:
    console_config_edits:
      - key: clusterInfo#loggingPublicURL
        value: ""
  when:
    - openshift_web_console_install | default(true) | bool
    - openshift.common.version_gte_3_9
