# Copies the istio definition file and removes the namespace from it
# This is done some we can avoid deleting the namespace
# At the end a variable named istio_copied_definition_file_full_path will be available which contains the path
# of the new file
- import_tasks: create_namespace_free_definition_file.yml

- name: Delete Jaeger info
  shell: |
    {{ cmd_path }} process -f https://raw.githubusercontent.com/jaegertracing/jaeger-openshift/master/all-in-one/jaeger-all-in-one-template.yml | {{ cmd_path }} delete --ignore-not-found=true -f -
    {{ cmd_path }} delete svc jaeger --ignore-not-found=true
  ignore_errors: true

- name: Delete Kiali info
  shell: |
    {{ cmd_path }} delete all,secrets,sa,templates,configmaps,deployments,clusterroles,clusterrolebindings,virtualservices,destinationrules  --selector=app=kiali --selector=version=master --ignore-not-found=true -n {{ istio_namespace }}
  ignore_errors: true

- name: Delete content from Istio Kubernetes file
  command: "{{ cmd_path }} delete -f {{ istio_copied_definition_file_full_path }} --ignore-not-found=true -n {{ istio_namespace }}"
  when: not istio.auth
  ignore_errors: true

- name: Delete whatever else might be left over
  command: "{{ cmd_path }} delete all --all -n {{ item }}"
  ignore_errors: true
  with_items:
    - "{{ istio_namespace }}"
    - samples
    - bookinfo

- name: Wait for the previous command to complete
  pause:
    seconds: 30
