|
| 1 | +--- |
| 2 | +# This is a pre_infra ci-framework hook that will configure the cluster for |
| 3 | +# disconnected deployment. The variable: cifmw_ci_gen_kustomize_values_ooi_image |
| 4 | +# must be specified. These examples for that variable are supported: |
| 5 | +# |
| 6 | +# registry-proxy.engineering.redhat.com/rh-osbs/iib:1125611 |
| 7 | +# registry.redhat.io/redhat/redhat-operator-index:v4.18 |
| 8 | +# |
| 9 | +# Due to being in deprecated sqlite format this is unsupported: |
| 10 | +# images.paas.redhat.com/podified-main-rhos-18-rhel-9/openstack-operator-index:trunk-patches-latest |
| 11 | +# |
| 12 | +# sqlite requires deprecated v1 oc-mirror workflow instead of the supported v2 |
| 13 | +# oc-mirror workflow |
| 14 | +# |
| 15 | +# |
| 16 | +- name: Update cluster for disconnected deployment |
| 17 | + hosts: "{{ cifmw_target_host | default('localhost') }}" |
| 18 | + vars: |
| 19 | + oc_mirror_download_url: "{{ cifmw_disconnected_mirror_url | default('https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/oc-mirror.rhel9.tar.gz') }}" |
| 20 | + mirror_registry_url: "{{ cifmw_disconnected_registry_url | default('https://mirror.openshift.com/pub/cgw/mirror-registry/latest/mirror-registry-amd64.tar.gz') }}" |
| 21 | + openstack_namespace: "{{ cifmw_openstack_namespace | default('openstack') }}" |
| 22 | + disconnect_working_dir: "{{ cifmw_disconnected_working_dir | default('/home/zuul/disconnect_working_dir') }}" |
| 23 | + mirror_location: "{{ disconnect_working_dir }}/mirror_location" |
| 24 | + local_registry: "{{ disconnect_working_dir }}/local_registry" |
| 25 | + oc_mirror_cert_manager_catalog_url: "{{ cifmw_cert_manager_catalog_url | default('registry.redhat.io/redhat/redhat-operator-index:v4.18') }}" |
| 26 | + tasks: |
| 27 | + - name: Create disconnected working directories |
| 28 | + ansible.builtin.file: |
| 29 | + path: "{{ item }}" |
| 30 | + state: directory |
| 31 | + mode: '0777' |
| 32 | + loop: |
| 33 | + - "{{ disconnect_working_dir }}" |
| 34 | + - "{{ mirror_location }}" |
| 35 | + - "{{ local_registry }}" |
| 36 | + |
| 37 | + - name: Download oc mirror image to controller |
| 38 | + ansible.builtin.get_url: |
| 39 | + url: "{{ oc_mirror_download_url }}" |
| 40 | + dest: "{{ disconnect_working_dir }}/oc-mirror.rhel9.tar.gz" |
| 41 | + mode: '0644' |
| 42 | + |
| 43 | + - name: Extract downloaded oc mirror archive |
| 44 | + ansible.builtin.unarchive: |
| 45 | + src: "{{ disconnect_working_dir }}/oc-mirror.rhel9.tar.gz" |
| 46 | + dest: "{{ disconnect_working_dir }}" |
| 47 | + remote_src: true |
| 48 | + |
| 49 | + - name: Install oc mirror |
| 50 | + ansible.builtin.shell: | |
| 51 | + set -eux |
| 52 | + chmod +x {{ disconnect_working_dir }}/oc-mirror && |
| 53 | + sudo mv {{ disconnect_working_dir }}/oc-mirror /usr/local/bin/. |
| 54 | +
|
| 55 | + - name: Get host FQDN |
| 56 | + ansible.builtin.command: hostname -f |
| 57 | + register: host_fqdn |
| 58 | + |
| 59 | + - name: Create mirror location file |
| 60 | + become: true |
| 61 | + ansible.builtin.copy: |
| 62 | + dest: "/etc/containers/registries.conf.d/010-stage.conf" |
| 63 | + content: | |
| 64 | + unqualified-search-registries = ["registry.access.redhat.com", "docker.io"] |
| 65 | + short-name-mode = "" |
| 66 | +
|
| 67 | + [[registry]] |
| 68 | + prefix = "" |
| 69 | + location = "registry.redhat.io" |
| 70 | +
|
| 71 | + [[registry.mirror]] |
| 72 | + location = "registry.stage.redhat.io" |
| 73 | + pull-from-mirror = "digest-only" |
| 74 | +
|
| 75 | + - name: Create update service namespace |
| 76 | + cifmw.general.ci_script: |
| 77 | + output_dir: "{{ cifmw_basedir }}/artifacts" |
| 78 | + script: | |
| 79 | + oc apply -f - <<EOF |
| 80 | + apiVersion: v1 |
| 81 | + kind: Namespace |
| 82 | + metadata: |
| 83 | + name: openshift-update-service |
| 84 | + annotations: |
| 85 | + openshift.io/node-selector: "" |
| 86 | + labels: |
| 87 | + openshift.io/cluster-monitoring: "true" |
| 88 | + EOF |
| 89 | +
|
| 90 | + - name: Create update service operator group |
| 91 | + cifmw.general.ci_script: |
| 92 | + output_dir: "{{ cifmw_basedir }}/artifacts" |
| 93 | + script: | |
| 94 | + oc apply -f - <<EOF |
| 95 | + apiVersion: operators.coreos.com/v1 |
| 96 | + kind: OperatorGroup |
| 97 | + metadata: |
| 98 | + name: update-service-operator-group |
| 99 | + namespace: openshift-update-service |
| 100 | + spec: |
| 101 | + targetNamespaces: |
| 102 | + - openshift-update-service |
| 103 | + EOF |
| 104 | +
|
| 105 | + - name: Create subscription service |
| 106 | + cifmw.general.ci_script: |
| 107 | + output_dir: "{{ cifmw_basedir }}/artifacts" |
| 108 | + script: | |
| 109 | + oc apply -f - <<EOF |
| 110 | + apiVersion: operators.coreos.com/v1alpha1 |
| 111 | + kind: Subscription |
| 112 | + metadata: |
| 113 | + name: update-service-subscription |
| 114 | + namespace: openshift-update-service |
| 115 | + spec: |
| 116 | + channel: v1 |
| 117 | + installPlanApproval: "Automatic" |
| 118 | + source: "redhat-operators" |
| 119 | + sourceNamespace: "openshift-marketplace" |
| 120 | + name: "cincinnati-operator" |
| 121 | + EOF |
| 122 | +
|
| 123 | + - name: Wait for update service operator to be installed |
| 124 | + ansible.builtin.shell: | |
| 125 | + set -o pipefail |
| 126 | + oc get crd | grep -i updateservice.operator.openshift.io |
| 127 | + register: crd_out |
| 128 | + until: "'updateservice.operator.openshift.io' in crd_out.stdout" |
| 129 | + retries: 10 |
| 130 | + delay: 30 |
| 131 | + |
| 132 | + - name: Create Image Set yaml when two catalogs are required |
| 133 | + ansible.builtin.copy: |
| 134 | + dest: "{{ disconnect_working_dir }}/imageset-config-v2.yaml" |
| 135 | + content: | |
| 136 | + kind: ImageSetConfiguration |
| 137 | + apiVersion: mirror.openshift.io/v2alpha1 |
| 138 | + mirror: |
| 139 | + operators: |
| 140 | + - catalog: {{ cifmw_ci_gen_kustomize_values_ooi_image }} |
| 141 | + packages: |
| 142 | + - name: openstack-operator |
| 143 | + - name: local-storage-operator |
| 144 | + - catalog: {{ oc_mirror_cert_manager_catalog_url }} |
| 145 | + packages: |
| 146 | + - name: kubernetes-nmstate-operator |
| 147 | + - name: openshift-cert-manager-operator |
| 148 | + - name: metallb-operator |
| 149 | + - name: lvms-operator |
| 150 | + - name: cluster-observability-operator |
| 151 | + additionalImages: |
| 152 | + - name: registry.redhat.io/ubi8/ubi:latest |
| 153 | + - name: registry.redhat.io/ubi9/ubi@sha256:20f695d2a91352d4eaa25107535126727b5945bff38ed36a3e59590f495046f0 |
| 154 | + when: cifmw_ci_gen_kustomize_values_ooi_image != oc_mirror_cert_manager_catalog_url |
| 155 | + |
| 156 | + - name: Create Image Set yaml when only one catalog is required |
| 157 | + ansible.builtin.copy: |
| 158 | + dest: "{{ disconnect_working_dir }}/imageset-config-v2.yaml" |
| 159 | + content: | |
| 160 | + kind: ImageSetConfiguration |
| 161 | + apiVersion: mirror.openshift.io/v2alpha1 |
| 162 | + mirror: |
| 163 | + operators: |
| 164 | + - catalog: {{ cifmw_ci_gen_kustomize_values_ooi_image }} |
| 165 | + packages: |
| 166 | + - name: openstack-operator |
| 167 | + - name: local-storage-operator |
| 168 | + - name: kubernetes-nmstate-operator |
| 169 | + - name: openshift-cert-manager-operator |
| 170 | + - name: metallb-operator |
| 171 | + - name: lvms-operator |
| 172 | + - name: cluster-observability-operator |
| 173 | + additionalImages: |
| 174 | + - name: registry.redhat.io/ubi8/ubi:latest |
| 175 | + - name: registry.redhat.io/ubi9/ubi@sha256:20f695d2a91352d4eaa25107535126727b5945bff38ed36a3e59590f495046f0 |
| 176 | + when: cifmw_ci_gen_kustomize_values_ooi_image == oc_mirror_cert_manager_catalog_url |
| 177 | + |
| 178 | + - name: Get registry.redhat.io username and password from pull secret |
| 179 | + ansible.builtin.shell: | |
| 180 | + set -o pipefail |
| 181 | + oc get -n openshift-config secret pull-secret -o json | jq '.data[".dockerconfigjson"]' -r | base64 -d | jq '.auths["registry.redhat.io"].auth' -r | base64 -d |
| 182 | + register: pull_secret_user_pass |
| 183 | + |
| 184 | + - name: Login to registry.redhat.io |
| 185 | + containers.podman.podman_login: |
| 186 | + username: "{{ pull_secret_user_pass.stdout.split(':')[0] }}" |
| 187 | + password: "{{ pull_secret_user_pass.stdout.split(':')[1] }}" |
| 188 | + registry: "registry.redhat.io" |
| 189 | + |
| 190 | + - name: Login to registry.stage.redhat.io |
| 191 | + containers.podman.podman_login: |
| 192 | + username: "{{ cifmw_registry_token.credentials.username }}" |
| 193 | + password: "{{ cifmw_registry_token.credentials.password }}" |
| 194 | + registry: "registry.stage.redhat.io" |
| 195 | + |
| 196 | + - name: Mirror specified image set configuration to disk |
| 197 | + ansible.builtin.shell: | |
| 198 | + oc mirror --v2 --config {{ disconnect_working_dir }}/imageset-config-v2.yaml file://{{ mirror_location }} >>{{ disconnect_working_dir }}/mirror_images.log |
| 199 | + register: mirror_image_result |
| 200 | + until: mirror_image_result is not failed |
| 201 | + retries: 1 |
| 202 | + |
| 203 | + - name: Download mirror registry to controller |
| 204 | + ansible.builtin.get_url: |
| 205 | + url: "{{ mirror_registry_url }}" |
| 206 | + dest: "{{ disconnect_working_dir }}/mirror-registry-amd64.tar.gz" |
| 207 | + mode: '0644' |
| 208 | + |
| 209 | + - name: Extract downloaded mirror registry archive |
| 210 | + ansible.builtin.unarchive: |
| 211 | + src: "{{ disconnect_working_dir }}/mirror-registry-amd64.tar.gz" |
| 212 | + dest: "{{ disconnect_working_dir }}" |
| 213 | + remote_src: true |
| 214 | + |
| 215 | + - name: Install mirror registry |
| 216 | + ansible.builtin.shell: | |
| 217 | + {{ disconnect_working_dir }}/mirror-registry install --quayHostname {{ host_fqdn.stdout }} --quayRoot \ |
| 218 | + {{ local_registry }} --initPassword {{ cifmw_mirror_registry_init_password }} >{{ disconnect_working_dir }}/registry_install.log |
| 219 | +
|
| 220 | + - name: Increase gunicorn-web timeout in quay-app container |
| 221 | + ansible.builtin.command: >- |
| 222 | + podman exec -it quay-app {% raw %}sed -i '/command=gunicorn |
| 223 | + -c %(ENV_QUAYCONF)s\/gunicorn_web.py web:application/c\command=gunicorn |
| 224 | + --timeout 900 -c %(ENV_QUAYCONF)s\/gunicorn_web.py web:application' |
| 225 | + /quay-registry/conf/supervisord.conf{% endraw %} |
| 226 | +
|
| 227 | + - name: Reread supervisord.conf in quay-app container |
| 228 | + ansible.builtin.command: |
| 229 | + podman exec -it quay-app supervisorctl -c /quay-registry/conf/supervisord.conf help reread |
| 230 | + |
| 231 | + - name: Restart gunicorn-web quay-app container with new timeout value |
| 232 | + ansible.builtin.command: |
| 233 | + podman exec -it quay-app supervisorctl -c /quay-registry/conf/supervisord.conf restart gunicorn-web |
| 234 | + |
| 235 | + - name: Configure system to trust mirror registry root ca |
| 236 | + become: true |
| 237 | + ansible.builtin.shell: | |
| 238 | + cp {{ local_registry }}/quay-rootCA/rootCA.pem /etc/pki/ca-trust/source/anchors/ |
| 239 | + update-ca-trust extract |
| 240 | +
|
| 241 | + - name: Login to mirror registry |
| 242 | + containers.podman.podman_login: |
| 243 | + username: "init" |
| 244 | + password: "{{ cifmw_mirror_registry_init_password }}" |
| 245 | + registry: "{{ host_fqdn.stdout }}:8443" |
| 246 | + |
| 247 | + - name: Configure cluster to trust mirror registry root ca |
| 248 | + ansible.builtin.shell: | |
| 249 | + set -eux |
| 250 | + oc create configmap registry-cas -n openshift-config --from-file={{ host_fqdn.stdout }}..8443={{ local_registry }}/quay-rootCA/rootCA.pem |
| 251 | + oc patch image.config.openshift.io/cluster --patch '{"spec":{"additionalTrustedCA":{"name":"registry-cas"}}}' --type=merge |
| 252 | +
|
| 253 | + - name: Get cluster's current pull secret |
| 254 | + ansible.builtin.shell: | |
| 255 | + oc get secret {% raw %}pull-secret -n openshift-config -o template='{{index .data ".dockerconfigjson" | base64decode}}'{% endraw %} > {{ disconnect_working_dir }}/pull-secret.json |
| 256 | +
|
| 257 | + - name: Configure cluster to use pull secret from mirror registry |
| 258 | + ansible.builtin.shell: | |
| 259 | + set -eux |
| 260 | + oc registry login --registry {{ host_fqdn.stdout }}:8443 --auth-basic=init:{{ cifmw_mirror_registry_init_password }} --to={{ disconnect_working_dir }}/pull-secret.json |
| 261 | + oc set data secret/pull-secret -n openshift-config --from-file=.dockerconfigjson={{ disconnect_working_dir }}/pull-secret.json |
| 262 | +
|
| 263 | + - name: Mirror contents of generated image set to target mirror registry |
| 264 | + ansible.builtin.shell: | |
| 265 | + oc mirror --v2 --config {{ disconnect_working_dir }}/imageset-config-v2.yaml --from file://{{ mirror_location }} docker://{{ host_fqdn.stdout }}:8443 >>{{ disconnect_working_dir }}/mirror_contents.log |
| 266 | + register: mirror_contents_result |
| 267 | + until: mirror_contents_result is not failed |
| 268 | + retries: 1 |
| 269 | + |
| 270 | + - name: Disable catalog source |
| 271 | + ansible.builtin.shell: | |
| 272 | + oc patch OperatorHub cluster --type json -p '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": true}]' |
| 273 | +
|
| 274 | + - name: Extract image name and tag from catalog source |
| 275 | + ansible.builtin.set_fact: |
| 276 | + index_image_name_tag: "{{ oc_mirror_cert_manager_catalog_url.split('/') | last | replace(':', '-') | replace('.', '-') }}" |
| 277 | + |
| 278 | + - name: Prepare catalog source for environment |
| 279 | + ansible.builtin.replace: |
| 280 | + path: "{{ mirror_location }}/working-dir/cluster-resources/cs-{{ index_image_name_tag }}.yaml" |
| 281 | + regexp: cs-{{ index_image_name_tag }} |
| 282 | + replace: 'redhat-operators' |
| 283 | + |
| 284 | + - name: Apply yaml files from results directory to cluster |
| 285 | + ansible.builtin.shell: | |
| 286 | + oc apply -f {{ mirror_location }}/working-dir/cluster-resources |
| 287 | +
|
| 288 | + - name: Wait for mirrored operators to be available |
| 289 | + ansible.builtin.shell: | |
| 290 | + oc get packagemanifests.packages.operators.coreos.com |
| 291 | + register: packagemanifest_out |
| 292 | + until: |
| 293 | + - "'openstack-operator' in packagemanifest_out.stdout" |
| 294 | + - "'kubernetes-nmstate-operator' in packagemanifest_out.stdout" |
| 295 | + retries: 10 |
| 296 | + delay: 30 |
| 297 | + |
| 298 | + - name: Wait until the OpenShift cluster is stable |
| 299 | + ansible.builtin.command: |
| 300 | + oc adm wait-for-stable-cluster --minimum-stable-period=5s --timeout=30m |
0 commit comments