main.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. #- name: Store the credentials as a fact
  84. # set_fact:
  85. # sso_secret: '{"auths": {"quay.io": {"username": "{{ robot_username }}", "password": "{{ robot_token }}", "auth": "{{ (robot_username + ":" + robot_token) | string | b64encode }}"}}}'
  86. # NOTE: dot-keys aren't welcome for some dumb reason. Must use imperative command here.
  87. - name: Create a secret to access the catalog image if not yet there
  88. #k8s:
  89. # kubeconfig: tmp/kubeconfig-ocp4
  90. # validate_certs: no
  91. # state: present
  92. # api_version: v1
  93. # kind: secret
  94. # namespace: openshift-marketplace
  95. # name: catalogsecret
  96. # definition:
  97. # type: "kubernetes.io/dockerconfigjson"
  98. # data:
  99. # .dockerconfigjson: "{{ sso_secret | string | b64encode }}"
  100. 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 }}
  101. when: |-
  102. sso_sec_removed.changed or
  103. (sso_sec.resources is not defined) or
  104. ((sso_sec.resources | length) == 0) or
  105. (sso_sec.resources[0].data[".dockerconfigjson"] is not defined)
  106. - name: Get info about the rhsso-operator
  107. k8s_info:
  108. kubeconfig: tmp/kubeconfig-ocp4
  109. validate_certs: no
  110. api_version: packages.operators.coreos.com/v1
  111. kind: packagemanifest
  112. namespace: openshift-marketplace
  113. name: rhsso-operator
  114. register: sso_mft
  115. # TODO: remove the catalogsource also if it's not referencing the secret, the
  116. # pod is older than the secret, or its state is not "running"
  117. - name: Remove existing catalogsource from openshift-marketplace if rhsso-operator belongs to it
  118. k8s:
  119. kubeconfig: tmp/kubeconfig-ocp4
  120. validate_certs: no
  121. api_version: operators.coreos.com/v1alpha1
  122. kind: catalogsource
  123. namespace: openshift-marketplace
  124. name: do280-catalog
  125. state: absent
  126. when:
  127. - sso_mft.resources is defined
  128. - (sso_mft.resources | length) > 0
  129. - sso_mft.resources[0].status.catalogSource == "do280-catalog"
  130. # TODO: Wait for the do280-catalog pod to disappear.
  131. - name: Make certain the "standard" catalog source is updated
  132. k8s:
  133. kubeconfig: tmp/kubeconfig-ocp4
  134. validate_certs: no
  135. api_version: operators.coreos.com/v1alpha1
  136. kind: catalogsource
  137. namespace: openshift-marketplace
  138. name: do280-catalog
  139. state: present
  140. definition:
  141. spec:
  142. displayName: "do280 Operator Catalog"
  143. image: "quay.io/rhtuser/do280-catalog-nosso:v4.10"
  144. publisher: "Red Hat"
  145. secrets:
  146. - "catalogsecret"
  147. sourceType: "grpc"
  148. - name: Ensure the RHSSO catalog source is there as well
  149. k8s:
  150. kubeconfig: tmp/kubeconfig-ocp4
  151. validate_certs: no
  152. api_version: operators.coreos.com/v1alpha1
  153. kind: catalogsource
  154. namespace: openshift-marketplace
  155. name: do280-sso
  156. state: present
  157. definition:
  158. spec:
  159. displayName: "do280 SSO Catalog"
  160. image: "quay.io/rhtuser/do280-sso-operator:v4.10"
  161. publisher: "Red Hat"
  162. secrets:
  163. - "catalogsecret"
  164. sourceType: "grpc"
  165. # TODO: maybe both catalogsources?
  166. - name: Wait for the catalogsource to be ready.
  167. k8s_info:
  168. kubeconfig: tmp/kubeconfig-ocp4
  169. validate_certs: no
  170. api_version: operators.coreos.com/v1alpha1
  171. kind: catalogsource
  172. namespace: openshift-marketplace
  173. name: do280-sso
  174. register: sso_cat
  175. until:
  176. - (sso_cat.resources | length) == 1
  177. - sso_cat.resources[0].status is defined
  178. - sso_cat.resources[0].status.connectionState.lastObservedState == "READY"
  179. retries: 30
  180. delay: 10
  181. - name: Wait for the rhsso-operator packagemanifest to appear.
  182. k8s_info:
  183. kubeconfig: tmp/kubeconfig-ocp4
  184. validate_certs: no
  185. api_version: packages.operators.coreos.com/v1
  186. kind: packagemanifest
  187. namespace: openshift-marketplace
  188. name: rhsso-operator
  189. register: sso_mft
  190. until:
  191. - (sso_mft.resources | length) == 1
  192. - sso_mft.resources[0].status.catalogSource == "do280-sso"
  193. - sso_mft.resources[0].status.packageName == "rhsso-operator"
  194. retries: 30
  195. delay: 10
  196. - assert:
  197. that:
  198. - sso_mft.resources is defined
  199. - (sso_mft.resources | length) > 0
  200. - sso_mft.resources[0].status.catalogSource == "do280-sso"
  201. - '"rhsso-operator.7.6.0-opr-003" in (sso_mft.resources[0] | community.general.json_query("status.channels[*].currentCSV") | list)'
  202. fail_msg: "ERROR: rhsso-operator package manifest not deployed correctly."
  203. success_msg: "OK: rhsso-operator package manifest configured correctly."
  204. ...