main.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. - name: Remove existing catalogsource from openshift-marketplace if rhsso-operator belongs to it
  116. k8s:
  117. kubeconfig: tmp/kubeconfig-ocp4
  118. validate_certs: no
  119. api_version: operators.coreos.com/v1alpha1
  120. kind: catalogsource
  121. namespace: openshift-marketplace
  122. name: do280-catalog
  123. state: absent
  124. when:
  125. - sso_mft.resources is defined
  126. - (sso_mft.resources | length) > 0
  127. - sso_mft.resources[0].status.catalogSource == "do280-catalog"
  128. # TODO: remove the catalogsource also if it's not referencing the secret, the
  129. # pod is older than the secret, or its state is not "running"
  130. - name: Make certain the "standard" catalog source is updated
  131. k8s:
  132. kubeconfig: tmp/kubeconfig-ocp4
  133. validate_certs: no
  134. api_version: operators.coreos.com/v1alpha1
  135. kind: catalogsource
  136. namespace: openshift-marketplace
  137. name: do280-catalog
  138. state: present
  139. definition:
  140. spec:
  141. displayName: "do280 Operator Catalog"
  142. image: "quay.io/rhtuser/do280-catalog-nosso:v4.10"
  143. publisher: "Red Hat"
  144. secrets:
  145. - "catalogsecret"
  146. sourceType: "grpc"
  147. - name: Ensure the RHSSO catalog source is there as well
  148. k8s:
  149. kubeconfig: tmp/kubeconfig-ocp4
  150. validate_certs: no
  151. api_version: operators.coreos.com/v1alpha1
  152. kind: catalogsource
  153. namespace: openshift-marketplace
  154. name: do280-sso
  155. state: present
  156. definition:
  157. spec:
  158. displayName: "do280 SSO Catalog"
  159. image: "quay.io/rhtuser/do280-sso-operator:v4.10"
  160. publisher: "Red Hat"
  161. secrets:
  162. - "catalogsecret"
  163. sourceType: "grpc"
  164. # TODO: maybe both catalogsources?
  165. - name: Wait for the catalogsource to be ready.
  166. k8s_info:
  167. kubeconfig: tmp/kubeconfig-ocp4
  168. validate_certs: no
  169. api_version: operators.coreos.com/v1alpha1
  170. kind: catalogsource
  171. namespace: openshift-marketplace
  172. name: do280-sso
  173. register: sso_cat
  174. until:
  175. - (sso_cat.resources | length) == 1
  176. - sso_cat.resources[0].status is defined
  177. - sso_cat.resources[0].status.connectionState.lastObservedState == "READY"
  178. retries: 30
  179. delay: 10
  180. # TODO: wait for the do280-catalog and do280-sso pods to be back up as well?
  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. ...