main.yml 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ---
  2. # Ensures all the operator artifacts are created and waits for CSV to succeed.
  3. #
  4. # The following variables must exist:
  5. #
  6. # removed_operators: a list of below dictionaries
  7. # - sub_nspc subscription namespace
  8. # sub_name subscription name
  9. # csv_name CSV name to check for
  10. # pre_cleanup pre-cleanup tasks, a list of rtypes to remove (ALL)
  11. # - apiv api version
  12. # kind resource kind
  13. # nspc namespace (required for namespaced resources)
  14. # wait_for_gone whether to wait for the resource to disappear
  15. # wait_for_sec how long (in seconds) to wait for gone
  16. # add_cleanup additional CRDs to remove post-uninstall, a list of
  17. # - name crd name, OR
  18. # label crd label, in case both are defined, both are used
  19. #
  20. # This role must then be applied as:
  21. #
  22. # - include_role:
  23. # name: remove-operators
  24. # loop: "{{ removed_operators }}"
  25. # loop_control:
  26. # loop_var: role
  27. #
  28. # What this means is that each item of removed_operators is expected to be
  29. # placed in the "role" variable prior to iterating over this role.
  30. #
  31. # Must include tasks because you can't loop over a block.
  32. - name: Remove any of the resources found from pre_cleanup
  33. include_tasks: tasks/pre-cleanup.yml
  34. loop: "{{ role.pre_cleanup }}"
  35. loop_control:
  36. label: "{{ item.kind }}.{{ item.apiv }}"
  37. - name: Remove the subscription
  38. k8s:
  39. kubeconfig: tmp/kubeconfig-ocp4
  40. validate_certs: no
  41. api_version: operators.coreos.com/v1alpha1
  42. kind: subscription
  43. name: "{{ role.sub_name }}"
  44. namespace: "{{ role.sub_nspc }}"
  45. state: absent
  46. ignore_errors: yes
  47. - name: Remove the CSV as well, if so required
  48. k8s:
  49. kubeconfig: tmp/kubeconfig-ocp4
  50. validate_certs: no
  51. api_version: operators.coreos.com/v1alpha1
  52. kind: clusterserviceversion
  53. name: "{{ role.csv_name }}"
  54. namespace: "{{ role.sub_nspc }}"
  55. state: absent
  56. ignore_errors: yes
  57. when: role.csv_kill
  58. - name: Do post-cleanup
  59. k8s:
  60. kubeconfig: tmp/kubeconfig-ocp4
  61. validate_certs: no
  62. api_version: apiextensions.k8s.io/v1
  63. kind: customresourcedefinition
  64. name: "{{ item.name | default(omit) }}"
  65. label_selectors:
  66. - "{{ item.label | default(omit) }}"
  67. state: absent
  68. ignore_errors: yes
  69. loop: "{{ role.add_cleanup }}"
  70. - name: Lastly, remove the namespace, if instructed
  71. k8s:
  72. kubeconfig: tmp/kubeconfig-ocp4
  73. validate_certs: no
  74. api_version: v1
  75. kind: namespace
  76. name: "{{ role.sub_nspc }}"
  77. state: absent
  78. ignore_errors: yes
  79. when: role.nsp_kill
  80. ...