main.yml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. ---
  2. # Fixes the openshift-marketplace catalog by recreating it from a new image minus rhsso-operator.
  3. # After that, adds a new catalogsource containing the correct rhsso-operator package.
  4. #
  5. # References:
  6. # https://docs.openshift.com/container-platform/4.11/operators/admin/olm-restricted-networks.html
  7. # https://docs.openshift.com/container-platform/4.11/operators/admin/olm-managing-custom-catalogs.html
  8. # https://access.redhat.com/documentation/en-us/openshift_container_platform/4.9/html/cli_tools/opm-cli
  9. #
  10. # Prep Cheat-sheet:
  11. #
  12. # 1. Get rid of rhsso-operator in the do280-catalog:
  13. #
  14. # - get a list of existing packages in the do280-catalog
  15. #
  16. # oc port-forward do280-catalog-foobar 50051:50051
  17. # grpcurl -plaintext localhost:50051 api.Registry/ListPackages > do280-packages.json
  18. #
  19. # - remove rhsso-operator from do280-operator-catalog and push create a new image
  20. #
  21. # opm index prune --from-index quay.io/redhattraining/do280-operator-catalog:v4.10 --tag quay.io/rhtuser/do280-catalog-nosso:v4.10 -p $(grep name do280-packages.json | sed 's/^.*name": "//; s/"$//' | grep -v rhsso-operator | tr '\n' ',' | sed 's/,$//')
  22. #
  23. # - push the new image up (AUTHENTICATION!)
  24. #
  25. # podman push quay.io/rhtuser/do280-catalog-nosso:v4.10
  26. #
  27. # 2. Get the latest version of rhsso-operator:
  28. #
  29. # - take the original operator index (latest version) and prune it of everything but rhsso-operator
  30. #
  31. # opm index prune --from-index registry.redhat.io/redhat/redhat-operator-index:v4.10 --tag quay.io/rhtuser/do280-sso-operator:v4.10 -p rhsso-operator
  32. #
  33. # - push the image (AUTHENTICATION!)
  34. #
  35. # podman push quay.io/rhtuser/do280-sso-operator:v4.10
  36. #
  37. # NOTE: quay.io robot account rhtuser+rhsso must have read access to the above two images.
  38. # (creds in vars/main.yml)
  39. #
  40. # NOTE: Everything up until here has already been done and only needs to be done once.
  41. #
  42. # This is necessary immediately after lab create.
  43. - name: Wait for the marketplace-operator to be up
  44. k8s_info:
  45. kubeconfig: tmp/kubeconfig-ocp4
  46. validate_certs: no
  47. api_version: v1
  48. kind: pod
  49. namespace: openshift-marketplace
  50. label_selectors:
  51. - name=marketplace-operator
  52. register: mktplc_pod
  53. until:
  54. - (mktplc_pod.resources | length) == 1
  55. - mktplc_pod.resources[0].status.containerStatuses[0].ready
  56. retries: 30
  57. delay: 10
  58. - name: Get info about the SSO catalog secret
  59. k8s_info:
  60. kubeconfig: tmp/kubeconfig-ocp4
  61. validate_certs: no
  62. api_version: v1
  63. kind: secret
  64. namespace: openshift-marketplace
  65. name: catalogsecret
  66. register: sso_sec
  67. - name: Get rid of the secret if anything is wrong with it
  68. k8s:
  69. kubeconfig: tmp/kubeconfig-ocp4
  70. validate_certs: no
  71. state: absent
  72. api_version: v1
  73. kind: secret
  74. namespace: openshift-marketplace
  75. name: catalogsecret
  76. register: sso_sec_removed
  77. when:
  78. - sso_sec.resources is defined
  79. - (sso_sec.resources | length) == 1
  80. - |-
  81. (sso_sec.resources[0].data[".dockerconfigjson"] is not defined) or
  82. (sso_sec.resources[0].type != "kubernetes.io/dockerconfigjson")
  83. # NOTE: dot-keys aren't welcome for some dumb reason. Must use imperative command here.
  84. - name: Create a secret to access the catalog image if not yet there
  85. #k8s:
  86. # kubeconfig: tmp/kubeconfig-ocp4
  87. # validate_certs: no
  88. # state: present
  89. # api_version: v1
  90. # kind: secret
  91. # namespace: openshift-marketplace
  92. # name: catalogsecret
  93. # definition:
  94. # type: "kubernetes.io/dockerconfigjson"
  95. # data:
  96. # .dockerconfigjson: "{{ sso_secret | string | b64encode }}"
  97. command: oc --kubeconfig=tmp/kubeconfig-ocp4 -n openshift-marketplace create secret docker-registry catalogsecret --docker-server=quay.io --docker-username={{ robot_username }} --docker-password={{ robot_token }}
  98. when: |-
  99. sso_sec_removed.changed or
  100. (sso_sec.resources is not defined) or
  101. ((sso_sec.resources | length) == 0) or
  102. (sso_sec.resources[0].data[".dockerconfigjson"] is not defined)
  103. - name: Get info about the rhsso-operator
  104. k8s_info:
  105. kubeconfig: tmp/kubeconfig-ocp4
  106. validate_certs: no
  107. api_version: packages.operators.coreos.com/v1
  108. kind: packagemanifest
  109. namespace: openshift-marketplace
  110. name: rhsso-operator
  111. register: sso_mft
  112. - name: Get info from the do280-catalog source
  113. k8s_info:
  114. kubeconfig: tmp/kubeconfig-ocp4
  115. validate_certs: no
  116. api_version: operators.coreos.com/v1alpha1
  117. kind: catalogsource
  118. namespace: openshift-marketplace
  119. name: do280-catalog
  120. register: op_catalog
  121. # TODO: remove the catalogsource also if the pod is older than the secret
  122. - name: Remove existing catalogsource from openshift-marketplace if rhsso-operator belongs to it
  123. k8s:
  124. kubeconfig: tmp/kubeconfig-ocp4
  125. validate_certs: no
  126. api_version: operators.coreos.com/v1alpha1
  127. kind: catalogsource
  128. namespace: openshift-marketplace
  129. name: do280-catalog
  130. state: absent
  131. when: |-
  132. (sso_mft.resources is defined and
  133. (sso_mft.resources | length) > 0 and
  134. sso_mft.resources[0].status.catalogSource == "do280-catalog")
  135. or
  136. (op_catalog.resources is defined and
  137. (op_catalog.resources | length) > 0 and
  138. ((op_catalog.resources[0].spec.image != catalog_main_image) or
  139. (op_catalog.resources[0].spec.secrets is not defined) or
  140. (op_catalog.resources[0].spec.secrets != ["catalogsecret"])))
  141. - name: Make certain the "standard" catalog source is updated
  142. k8s:
  143. kubeconfig: tmp/kubeconfig-ocp4
  144. validate_certs: no
  145. api_version: operators.coreos.com/v1alpha1
  146. kind: catalogsource
  147. namespace: openshift-marketplace
  148. name: do280-catalog
  149. state: present
  150. definition:
  151. spec:
  152. displayName: "do280 Operator Catalog"
  153. image: "{{ catalog_main_image }}"
  154. publisher: "Red Hat"
  155. secrets:
  156. - "catalogsecret"
  157. sourceType: "grpc"
  158. register: op_catalog_modified
  159. - name: Ensure the RHSSO catalog source is there as well
  160. k8s:
  161. kubeconfig: tmp/kubeconfig-ocp4
  162. validate_certs: no
  163. api_version: operators.coreos.com/v1alpha1
  164. kind: catalogsource
  165. namespace: openshift-marketplace
  166. name: do280-sso
  167. state: present
  168. definition:
  169. spec:
  170. displayName: "do280 SSO Catalog"
  171. image: "{{ catalog_sso_image }}"
  172. publisher: "Red Hat"
  173. secrets:
  174. - "catalogsecret"
  175. sourceType: "grpc"
  176. - name: Wait for things to settle down a bit for do280-catalog
  177. pause:
  178. seconds: 10
  179. prompt: "Waiting for marketplace operator to settle down."
  180. when: op_catalog_modified.changed
  181. - name: Delete the do280-catalog pod if CS was modified
  182. k8s:
  183. kubeconfig: tmp/kubeconfig-ocp4
  184. validate_certs: no
  185. api_version: v1
  186. kind: pod
  187. namespace: openshift-marketplace
  188. label_selectors:
  189. - olm.catalogSource=do280-catalog
  190. state: absent
  191. when: op_catalog_modified.changed
  192. - name: Wait for the catalogsource to be ready.
  193. k8s_info:
  194. kubeconfig: tmp/kubeconfig-ocp4
  195. validate_certs: no
  196. api_version: operators.coreos.com/v1alpha1
  197. kind: catalogsource
  198. namespace: openshift-marketplace
  199. name: do280-sso
  200. register: sso_cat
  201. until:
  202. - (sso_cat.resources | length) == 1
  203. - sso_cat.resources[0].status is defined
  204. - sso_cat.resources[0].status.connectionState.lastObservedState == "READY"
  205. retries: 30
  206. delay: 10
  207. - name: Wait for the rhsso-operator packagemanifest to appear.
  208. k8s_info:
  209. kubeconfig: tmp/kubeconfig-ocp4
  210. validate_certs: no
  211. api_version: packages.operators.coreos.com/v1
  212. kind: packagemanifest
  213. namespace: openshift-marketplace
  214. name: rhsso-operator
  215. register: sso_mft
  216. until:
  217. - (sso_mft.resources | length) == 1
  218. - sso_mft.resources[0].status.catalogSource == "do280-sso"
  219. - sso_mft.resources[0].status.packageName == "rhsso-operator"
  220. retries: 30
  221. delay: 10
  222. - assert:
  223. that:
  224. - sso_mft.resources is defined
  225. - (sso_mft.resources | length) > 0
  226. - sso_mft.resources[0].status.catalogSource == "do280-sso"
  227. - '"rhsso-operator.7.6.0-opr-003" in (sso_mft.resources[0] | community.general.json_query("status.channels[*].currentCSV") | list)'
  228. fail_msg: "ERROR: rhsso-operator package manifest not deployed correctly."
  229. success_msg: "OK: rhsso-operator package manifest configured correctly."
  230. ...