|
| 1 | +--- |
| 2 | +# Copyright Red Hat, Inc. |
| 3 | +# All Rights Reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | +# not use this file except in compliance with the License. You may obtain |
| 7 | +# a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | +# License for the specific language governing permissions and limitations |
| 15 | +# under the License. |
| 16 | + |
| 17 | +# When mirror_images is enabled in dev-scripts, the pull-secret is replaced |
| 18 | +# with only the local mirror registry credentials during installation. |
| 19 | +# This task restores the original pull-secret post-installation to allow |
| 20 | +# pulling images from external registries for operators and other workloads. |
| 21 | + |
| 22 | +- name: Get original pull-secret content |
| 23 | + no_log: true |
| 24 | + ansible.builtin.slurp: |
| 25 | + src: "{{ cifmw_devscripts_repo_dir }}/pull_secret.json" |
| 26 | + register: _original_pull_secret |
| 27 | + |
| 28 | +- name: Get current cluster pull-secret |
| 29 | + no_log: true |
| 30 | + kubernetes.core.k8s_info: |
| 31 | + kubeconfig: "{{ cifmw_openshift_kubeconfig }}" |
| 32 | + api_key: "{{ cifmw_openshift_token | default(omit) }}" |
| 33 | + context: "{{ cifmw_openshift_context | default(omit) }}" |
| 34 | + kind: Secret |
| 35 | + name: pull-secret |
| 36 | + namespace: openshift-config |
| 37 | + register: _cluster_pull_secret_raw |
| 38 | + |
| 39 | +- name: Update cluster pull-secret |
| 40 | + no_log: true |
| 41 | + vars: |
| 42 | + _original_auths: "{{ (_original_pull_secret.content | b64decode | from_json).auths }}" |
| 43 | + _cluster_auths: "{{ (_cluster_pull_secret_raw.resources[0].data['.dockerconfigjson'] | b64decode | from_json).auths }}" |
| 44 | + _merged_pull_secret: |
| 45 | + auths: "{{ _cluster_auths | combine(_original_auths, recursive=true) }}" |
| 46 | + kubernetes.core.k8s: |
| 47 | + kubeconfig: "{{ cifmw_openshift_kubeconfig }}" |
| 48 | + api_key: "{{ cifmw_openshift_token | default(omit) }}" |
| 49 | + context: "{{ cifmw_openshift_context | default(omit) }}" |
| 50 | + state: present |
| 51 | + definition: |
| 52 | + apiVersion: v1 |
| 53 | + kind: Secret |
| 54 | + metadata: |
| 55 | + name: pull-secret |
| 56 | + namespace: openshift-config |
| 57 | + type: kubernetes.io/dockerconfigjson |
| 58 | + data: |
| 59 | + .dockerconfigjson: "{{ _merged_pull_secret | to_json | b64encode }}" |
| 60 | + |
| 61 | +- name: Wait for nodes to stabilize after pull-secret update |
| 62 | + kubernetes.core.k8s_info: |
| 63 | + kubeconfig: "{{ cifmw_openshift_kubeconfig }}" |
| 64 | + api_key: "{{ cifmw_openshift_token | default(omit) }}" |
| 65 | + context: "{{ cifmw_openshift_context | default(omit) }}" |
| 66 | + kind: Node |
| 67 | + register: _nodes |
| 68 | + retries: 20 |
| 69 | + delay: 30 |
| 70 | + until: >- |
| 71 | + _nodes.resources | length > 0 and |
| 72 | + _nodes.resources | selectattr('status.conditions', 'defined') | |
| 73 | + map(attribute='status.conditions') | flatten | |
| 74 | + selectattr('type', 'equalto', 'Ready') | |
| 75 | + selectattr('status', 'equalto', 'True') | |
| 76 | + list | length == (_nodes.resources | length) |
| 77 | +
|
| 78 | +- name: Re-enable OperatorHub default sources |
| 79 | + kubernetes.core.k8s_json_patch: |
| 80 | + kubeconfig: "{{ cifmw_openshift_kubeconfig }}" |
| 81 | + api_version: config.openshift.io/v1 |
| 82 | + kind: OperatorHub |
| 83 | + name: cluster |
| 84 | + patch: |
| 85 | + - op: replace |
| 86 | + path: /spec/disableAllDefaultSources |
| 87 | + value: false |
| 88 | + |
| 89 | +- name: Display pull-secret restoration status |
| 90 | + ansible.builtin.debug: |
| 91 | + msg: >- |
| 92 | + Pull-secret has been restored with original credentials while keeping local mirror registry access. |
| 93 | + OperatorHub default sources have been re-enabled to allow operator installation. |
0 commit comments