|
53 | 53 | spec: |
54 | 54 | imageDigestMirrors: "{{ cifmw_openshift_setup_digest_mirrors }}" |
55 | 55 |
|
| 56 | +- name: Add catalog registry credentials to cluster pull-secret |
| 57 | + when: |
| 58 | + - cifmw_openshift_setup_catalog_registry_credentials is defined |
| 59 | + - cifmw_openshift_setup_catalog_registry_credentials | length > 0 |
| 60 | + no_log: true |
| 61 | + block: |
| 62 | + - name: Get current cluster pull-secret |
| 63 | + kubernetes.core.k8s_info: |
| 64 | + kubeconfig: "{{ cifmw_openshift_kubeconfig }}" |
| 65 | + api_key: "{{ cifmw_openshift_token | default(omit) }}" |
| 66 | + context: "{{ cifmw_openshift_context | default(omit) }}" |
| 67 | + kind: Secret |
| 68 | + name: pull-secret |
| 69 | + namespace: openshift-config |
| 70 | + register: _cluster_pull_secret |
| 71 | + |
| 72 | + - name: Merge catalog registry auth into cluster pull-secret |
| 73 | + vars: |
| 74 | + _current_auths: >- |
| 75 | + {{ |
| 76 | + (_cluster_pull_secret.resources[0].data['.dockerconfigjson'] |
| 77 | + | b64decode | from_json).auths |
| 78 | + }} |
| 79 | + _catalog_auth: |
| 80 | + "{{ cifmw_openshift_setup_catalog_registry_credentials.registry }}": |
| 81 | + auth: >- |
| 82 | + {{ |
| 83 | + (cifmw_openshift_setup_catalog_registry_credentials.username ~ ':' |
| 84 | + ~ cifmw_openshift_setup_catalog_registry_credentials.password) |
| 85 | + | b64encode |
| 86 | + }} |
| 87 | + _merged: |
| 88 | + auths: "{{ _current_auths | combine(_catalog_auth) }}" |
| 89 | + kubernetes.core.k8s: |
| 90 | + kubeconfig: "{{ cifmw_openshift_kubeconfig }}" |
| 91 | + api_key: "{{ cifmw_openshift_token | default(omit) }}" |
| 92 | + context: "{{ cifmw_openshift_context | default(omit) }}" |
| 93 | + state: present |
| 94 | + definition: |
| 95 | + apiVersion: v1 |
| 96 | + kind: Secret |
| 97 | + metadata: |
| 98 | + name: pull-secret |
| 99 | + namespace: openshift-config |
| 100 | + type: kubernetes.io/dockerconfigjson |
| 101 | + data: |
| 102 | + .dockerconfigjson: "{{ _merged | to_json | b64encode }}" |
| 103 | + |
| 104 | +- name: Wait for MachineConfigPools to settle after registry changes |
| 105 | + when: |
| 106 | + - cifmw_openshift_setup_digest_mirrors is defined |
| 107 | + - cifmw_openshift_setup_digest_mirrors | length > 0 |
| 108 | + environment: |
| 109 | + KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}" |
| 110 | + PATH: "{{ cifmw_path }}" |
| 111 | + ansible.builtin.shell: |
| 112 | + cmd: | |
| 113 | + set -eo pipefail |
| 114 | + MCP_JSON=$(oc get mcp -o json) |
| 115 | + UPDATING=$(echo "$MCP_JSON" | jq -r ' |
| 116 | + .items[] | |
| 117 | + select( |
| 118 | + .status.conditions // [] | |
| 119 | + map(select(.type == "Updating" and .status == "True")) | |
| 120 | + length > 0 |
| 121 | + ) | .metadata.name') |
| 122 | + if [ -z "$UPDATING" ]; then |
| 123 | + echo "All MCPs settled." |
| 124 | + exit 0 |
| 125 | + fi |
| 126 | + echo "MCPs still updating: $UPDATING" |
| 127 | + exit 1 |
| 128 | + register: _mcp_settle |
| 129 | + until: _mcp_settle.rc == 0 |
| 130 | + retries: 60 |
| 131 | + delay: 30 |
| 132 | + changed_when: false |
| 133 | + |
56 | 134 | # If both ImageDigestMirrorSet and ImageTagMirrorSet are applied to the registries, |
57 | 135 | # ITMS acts as a fallback for tag-based pulls, while IDMS provides the primary |
58 | 136 | # secure source for digests |
|
0 commit comments