Skip to content

Commit 84c46b6

Browse files
committed
devscripts: Restore pull-secret post-installation when mirror_images is enabled
When mirror_images is enabled in dev-scripts (either explicitly or automatically for IPv6 deployments), the pull-secret is replaced with only the local mirror registry credentials during installation. This causes operator installation and workload deployments to fail because the cluster cannot authenticate to external registries like quay.io, registry.redhat.io, etc. This change adds post-installation logic to: - Merge the original pull-secret with the local mirror credentials - Update the cluster's pull-secret in openshift-config namespace - Re-enable OperatorHub default sources (disabled during mirroring) - Preserve ImageContentSourcePolicy manifests for mirror preference The merged pull-secret allows the cluster to pull from both the local mirror (when available) and external registries (as fallback), enabling operator installation while maintaining the benefits of image mirroring. This particularly helps IPv6 deployments where dev-scripts automatically sets MIRROR_IMAGES=true by default. Changes: - roles/devscripts/tasks/320_restore_pull_secret.yml (new) - roles/devscripts/tasks/300_post.yml - roles/devscripts/README.md Goal: The goal is to improve stability, especially for IPv6 jobs that operate behind the nat64-appliance VM for all external traffic. Assisted-By: Claude Code/claude-4.5-sonnet Signed-off-by: Harald Jensås <[email protected]>
1 parent 970e4d3 commit 84c46b6

File tree

4 files changed

+114
-1
lines changed

4 files changed

+114
-1
lines changed

docs/dictionary/en-custom.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ IDM
238238
IdP
239239
Idempotency
240240
idrac
241+
imagecontentsourcepolicy
241242
iface
242243
igfsbg
243244
igmp
@@ -419,6 +420,7 @@ openstackprovisioner
419420
openstacksdk
420421
openstackversion
421422
operatorgroup
423+
operatorhub
422424
opn
423425
orchestrator
424426
osd

roles/devscripts/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ networks.
1616
building the various needed files.
1717
* `devscripts_deploy`: Overlaps with the previous tag, and adds the actual
1818
deployment of devscripts managed services.
19-
* `devscripts_post`: Only runs the post-installation tasks.
2019

2120
## Parameters
2221

@@ -136,6 +135,18 @@ Allowed values can be found [here](https://mirror.openshift.com/pub/openshift-v4
136135
| extra_worker_disk | | The disk size to be set for each extra nodes. |
137136
| extra_worker_vcpu | | The number of vCPUs to be configured for each extra nodes. |
138137

138+
#### Registry and Image Mirroring
139+
140+
| Key | Default Value | Description |
141+
| --- | ------------- | ----------- |
142+
| mirror_images | `false` | When set to `true`, enables image mirroring to a local registry. This is useful for disconnected/air-gapped environments. **Note:** When enabled, the pull-secret and OperatorHub sources are automatically restored after installation to allow pulling images from external registries for operators and other workloads. |
143+
144+
**Important:** When `mirror_images` is enabled:
145+
- During installation, only the local mirror registry credentials are used
146+
- Post-installation, the original pull-secret is automatically merged with the local mirror credentials
147+
- OperatorHub default sources are re-enabled to allow operator installation
148+
- ImageContentSourcePolicy manifests remain in place to prefer the local mirror when available, with fallback to external registries
149+
139150
### Support keys in cifmw_devscripts_external_net
140151

141152
| Key | Description |

roles/devscripts/tasks/300_post.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
- not cifmw_devscripts_ocp_online | bool
2727
ansible.builtin.import_tasks: set_cluster_fact.yml
2828

29+
- name: Restore pull-secret if mirror_images is enabled
30+
when:
31+
- cifmw_devscripts_config.mirror_images | default(false) | bool
32+
tags:
33+
- devscripts_deploy
34+
ansible.builtin.include_tasks: 320_restore_pull_secret.yml
35+
2936
- name: Prepare for disk overlay configuration
3037
when:
3138
- not cifmw_devscripts_ocp_comply | bool
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)