# 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 Addons
  command: "{{ cmd_path }} delete -f {{ istio_dir }}/{{ istio_k8s_install_path }}/addons/{{ item }}.yaml --ignore-not-found=true -n {{ istio.namespace }}"
  ignore_errors: true
  with_items: "{{ istio_all_addons }}"

- name: Delete Addon ServiceAccounts
  command: "{{ cmd_path }} delete sa istio-{{ item }}-service-account --ignore-not-found=true -n {{ istio.namespace }}"
  ignore_errors: true
  with_items: "{{ istio_all_addons }}"

- 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 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