main.yml 4.2 KB

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