main.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ---
  2. # Ensures all the operator artifacts are created and waits for CSV to succeed.
  3. #
  4. # The following variables must exist:
  5. #
  6. # added_operators: (list)
  7. # - catalog: the catalog of the manifest
  8. # package: the name of the packagemanifest
  9. # subscription: the name of the subscription (optional, defaults to package)
  10. # channel: which channel to install from
  11. # namespace: target namespace for subscription
  12. # desired_csv: for verification - wait for this CSV to appear
  13. # og_namespaces: (list) operatorgroup namespaces
  14. #
  15. # This role must then be applied as:
  16. #
  17. # - include_role:
  18. # name: deploy-operators
  19. # loop: "{{ added_operators }}"
  20. # loop_control:
  21. # loop_var: role
  22. #
  23. # What this means is that each item of added_operators is expected to be
  24. # placed in the "role" variable prior to iterating over this role.
  25. #
  26. # NOTE: Do NOT test by checking for presence of API resources - they do not always get cleaned up.
  27. #
  28. #
  29. #
  30. # TODO: Maybe someday fix the JSONPath expression below. And figure out why check for a CSV.
  31. #- name: Check if the CSV exists already
  32. # k8s_info:
  33. # kubeconfig: tmp/kubeconfig-ocp4
  34. # validate_certs: no
  35. # api_version: operators.coreos.com/v1alpha1
  36. # kind: clusterserviceversion
  37. # register: all_csv
  38. #
  39. #- name: Find the wanted CSV among all CSVs
  40. # set_fact:
  41. # found_csv: "{{ (all_csv | community.general.json_query(\"resources[?metadata.name == \" + role.desired_csv + \"]\")) }}"
  42. # when:
  43. # - all_csv.resources is defined
  44. # - (all_csv.resources | length) > 0
  45. #
  46. #- name: Get details about the CSV if found
  47. # set_fact:
  48. # csv_ns: "{{ found_csv[0] | community.general.json_query('metadata.namespace') }}"
  49. # csv_name: "{{ found_csv[0] | community.general.json_query('metadata.name') }}"
  50. # when:
  51. # - found_csv is defined
  52. # - (found_csv | length) > 0
  53. - name: Make sure the namespace is there
  54. k8s:
  55. kubeconfig: tmp/kubeconfig-ocp4
  56. validate_certs: no
  57. api_version: v1
  58. kind: namespace
  59. name: "{{ role.namespace }}"
  60. # TODO: Finish this at some point.
  61. # TODO: Just apply from role.og_namespaces - finding an OG or just applying a default name.
  62. #- name: Make sure the namespace has a properly configured OperatorGroup
  63. # k8s_info:
  64. # kubeconfig: tmp/kubeconfig-ocp4
  65. # validate_certs: no
  66. # api_version: operators.coreos.com/v1
  67. # kind: operatorgroup
  68. # namespace: "{{ op_nsp }}"
  69. # register: found_opgrp
  70. - name: Also make sure there is a subscription
  71. k8s:
  72. kubeconfig: tmp/kubeconfig-ocp4
  73. validate_certs: no
  74. api_version: operators.coreos.com/v1alpha1
  75. kind: subscription
  76. namespace: "{{ role.namespace }}"
  77. name: "{{ role.subscription | default(role.package) }}"
  78. definition:
  79. spec:
  80. source: "{{ role.catalog }}"
  81. sourceNamespace: openshift-marketplace
  82. name: "{{ role.package }}"
  83. channel: "{{ role.channel }}"
  84. startingCSV: "{{ role.desired_csv }}"
  85. installPlanApproval: Automatic
  86. # TODO: Finish this at some point.
  87. #- name: Wait for installPlan to show up
  88. # k8s_info:
  89. # kubeconfig: tmp/kubeconfig-ocp4
  90. # validate_certs: no
  91. # api_version: operators.coreos.com/v1alpha1
  92. # kind: installplan
  93. # namespace: "{{ op_nsp }}"
  94. # register: installplan
  95. # until:
  96. # - installplan.resources is defined
  97. # - (installplan.resources | length) > 0
  98. # - installplan.resources[0].spec.approved
  99. # retries: 12
  100. # delay: 10
  101. - name: Wait for CSV to show up and complete
  102. k8s_info:
  103. kubeconfig: tmp/kubeconfig-ocp4
  104. validate_certs: no
  105. api_version: operators.coreos.com/v1alpha1
  106. kind: clusterserviceversion
  107. namespace: "{{ role.namespace }}"
  108. name: "{{ role.desired_csv }}"
  109. register: new_csv
  110. until:
  111. - new_csv.resources is defined
  112. - (new_csv.resources | length) > 0
  113. - new_csv.resources[0].status is defined
  114. - new_csv.resources[0].status.phase == "Succeeded"
  115. retries: 30
  116. delay: 10
  117. # TODO: Finish this at some point.
  118. #- name: Finally, wait for the pod
  119. # k8s_info:
  120. # kubeconfig: tmp/kubeconfig-ocp4
  121. # validate_certs: no
  122. # api_version: v1
  123. # kind: pod
  124. # namespace: rhsso
  125. # label_selectors:
  126. # - name = rhsso-operator
  127. # register: sso_pod
  128. # until:
  129. # - sso_pod.resources is defined
  130. # - (sso_pod.resources | length) > 0
  131. # - sso_pod.resources[0].status is defined
  132. # - sso_pod.resources[0].status.phase == "Running"
  133. # retries: 30
  134. # delay: 10
  135. ...