Skip to content

Commit 0495190

Browse files
committed
Rework IIB loading support
This adds multiple IIB support in order to cater for the ACM IIB case, where the MCE operator might be in another IIB completely. To load multiple IIB for different operators, one needs to set the env variables as follows: export OPERATOR=advanced-cluster-management,multicluster-engine export INDEX_IMAGES=registry-proxy.engineering.redhat.com/rh-osbs/iib:713808,registry-proxy.engineering.redhat.com/rh-osbs/iib:718034 It is implied that the first IIB is for the first operator in the list, and the second one for the latter. Tested gitops-iib and it all worked with no changes.
1 parent 20cb31e commit 0495190

9 files changed

Lines changed: 69 additions & 51 deletions

File tree

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ secrets-backend-none: ## Edits values files to remove secrets manager + ESO
113113
.PHONY: load-iib
114114
load-iib: ## CI target to install Index Image Bundles
115115
@set -e; if [ x$(INDEX_IMAGES) != x ]; then \
116-
for IIB in $(shell echo $(INDEX_IMAGES) | tr ',' '\n'); do \
117-
INDEX_IMAGE="$${IIB}" ansible-playbook common/ansible/playbooks/iib-ci/iib-ci.yaml; \
118-
done; \
116+
ansible-playbook common/ansible/playbooks/iib-ci/iib-ci.yaml; \
119117
else \
120118
echo "No INDEX_IMAGES defined. Bailing out"; \
121119
exit 1; \

ansible/roles/iib_ci/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ make EXTRA_HELM_OPTS="--set main.extraParameters[0].name=clusterGroup.subscripti
5656

5757
*Note*: In this case `acm` is the name of the subscription in `values-hub.yaml`
5858

59-
### OCP 4.13 and onwards
60-
61-
Since 4.13 supports an internal registry that can cope with v2 docker manifests, we
62-
use that. Run `make iib` with the following environment variables set:
63-
64-
* `INDEX_IMAGES=registry-proxy.engineering.redhat.com/rh-osbs/iib:492329`
65-
* `KUBEADMINPASS="11111-22222-33333-44444"`
66-
6759
## Useful commands
6860

6961
* List IIBs for an operator:

ansible/roles/iib_ci/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
rh_internal_registry: registry-proxy.engineering.redhat.com
2-
iib_image: "{{ lookup('env', 'INDEX_IMAGE') }}"
2+
iib_images: "{{ lookup('env', 'INDEX_IMAGES') }}"
33

44
kubeadminpass: "{{ lookup('env', 'KUBEADMINPASS') }}"
55

ansible/roles/iib_ci/tasks/fetch-operator-images.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# the operator name is defined in the variable "item". This
33
# set of tasks is to be included in a loop that goes over the
44
# needed operators
5-
- name: Get default channel in the IIB for "{{ item }}"
5+
- name: Get default channel in the IIB for "{{ item.key }}"
66
ansible.builtin.shell: |
7-
oc get -n "{{ internal_registry_ns }}" packagemanifests -l "catalog=iib-{{ iib }}" --field-selector "metadata.name={{ item }}" \
7+
oc get -n "{{ internal_registry_ns }}" packagemanifests -l "catalog=iib-{{ item.value['iib'] }}" --field-selector "metadata.name={{ item.key }}" \
88
-o jsonpath='{.items[0].status.defaultChannel}'
99
register: default_channel_raw
1010
retries: 10
@@ -15,9 +15,13 @@
1515
ansible.builtin.set_fact:
1616
default_channel: "{{ default_channel_raw.stdout }}"
1717

18-
- name: Get all related images in the IIB for "{{ item }}"
18+
- name: Print default channel
19+
ansible.builtin.debug:
20+
msg: "Default channel for {{ item.key }}: {{ default_channel }}"
21+
22+
- name: Get all related images in the IIB for "{{ item.key }}"
1923
ansible.builtin.shell: |
20-
oc get packagemanifests -l "catalog=iib-{{ iib }}" --field-selector "metadata.name={{ item }}" \
24+
oc get packagemanifests -l "catalog=iib-{{ item.value['iib'] }}" --field-selector "metadata.name={{ item.key }}" \
2125
-o jsonpath="{.items[0].status.channels[?(@.name==\"{{ default_channel }}\")].currentCSVDesc.relatedImages}"
2226
register: related_images_raw
2327
retries: 5
@@ -29,15 +33,15 @@
2933
related_images: "{{ related_images_raw.stdout }}"
3034

3135
# NOTE(bandini)
32-
# The following code is here to fund out what the operator bundle image is and to make
36+
# The following code is here to find out what the operator bundle image is and to make
3337
# sure it is on the internal registry.
3438
# This is all potentially hacky, but so far I could not find a single place in the cluster
3539
# where the olm.bundle image is available. The info is in there in the IIB, but it certainly
3640
# is not in any package manifest nor catalogsource. This is why we resort to invoking opm
3741
# alpha commands inside the IIB image locally
3842
- name: Pull the IIB locally
3943
ansible.builtin.command:
40-
podman pull "{{ iib_image }}"
44+
podman pull "{{ item.value['iib_image'] }}"
4145

4246
# $ opm alpha list channels /configs advanced-cluster-management
4347
# PACKAGE CHANNEL HEAD
@@ -46,7 +50,7 @@
4650
- name: Read the operator bundle from the default channel
4751
ansible.builtin.shell: |
4852
set -o pipefail
49-
podman run -it --rm "{{ iib_image }}" alpha list channels /configs "{{ item }}" | grep -E "(\s){{ default_channel }}(\s)" | awk '{ print $3 }'
53+
podman run -it --rm "{{ item.value['iib_image'] }}" alpha list channels /configs "{{ item.key }}" | grep -E "(\s){{ default_channel }}(\s)" | awk '{ print $3 }'
5054
register: bundle_channel_raw
5155

5256
- name: Set bundle fact
@@ -70,7 +74,7 @@
7074
- name: Get bundle image
7175
ansible.builtin.shell: |
7276
set -o pipefail
73-
podman run -it --rm "{{ iib_image }}" alpha list bundles /configs "{{ item }}" | grep -e "{{ default_channel }}\s\+{{ bundle_channel }}" | awk '{ print $NF }'
77+
podman run -it --rm "{{ item.value['iib_image'] }}" alpha list bundles /configs "{{ item.key }}" | grep -e "{{ default_channel }}\s\+{{ bundle_channel }}" | awk '{ print $NF }'
7478
register: bundle_image_raw
7579

7680
- name: Set bundle image fact

ansible/roles/iib_ci/tasks/install-iib-in-cluster.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
- name: Set IIB local folder fact
2+
ansible.builtin.set_fact:
3+
iib_local_folder: "/tmp/manifest-{{ item.value['iib'] }}"
4+
15
- name: Remove manifest folder "{{ iib_local_folder }}"
26
ansible.builtin.file:
37
path: "{{ iib_local_folder }}"
@@ -16,14 +20,14 @@
1620
- name: Mirror catalog manifests only to "{{ iib_local_folder }}"
1721
ansible.builtin.shell: |
1822
oc adm catalog mirror --insecure --manifests-only --to-manifests=. \
19-
"{{ iib_image }}" "{{ rh_internal_registry }}/rh-osbs" > catalog.log 2>&1
23+
"{{ item.value['iib_image'] }}" "{{ rh_internal_registry }}/rh-osbs" > catalog.log 2>&1
2024
args:
2125
chdir: "{{ iib_local_folder }}"
2226

2327
- name: Mirror IIB to "{{ mirror_iib }}"
2428
ansible.builtin.shell: |
2529
oc image mirror -a "{{ pull_secrets_tempfolder.path }}/.dockerconfigjson" \
26-
"{{ iib_image }}={{ mirror_iib }}" --insecure --keep-manifest-list 2>&1
30+
"{{ item.value['iib_image'] }}={{ mirror_iib }}" --insecure --keep-manifest-list 2>&1
2731
args:
2832
chdir: "{{ iib_local_folder }}"
2933
register: oc_mirror_result
@@ -43,7 +47,7 @@
4347
4448
- name: Wait for catalogsource to show up
4549
ansible.builtin.shell: |
46-
oc get -n "{{ internal_registry_ns }}" packagemanifests -l "catalog=iib-{{ iib }}" --field-selector "metadata.name={{ operator }}" \
50+
oc get -n "{{ internal_registry_ns }}" packagemanifests -l "catalog=iib-{{ item.value['iib'] }}" --field-selector "metadata.name={{ item.key }}" \
4751
-o jsonpath='{.items[0].status.defaultChannel}'
4852
register: oc_catalogsource_result
4953
retries: 30

ansible/roles/iib_ci/tasks/main.yml

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
- name: Check that INDEX_IMAGE env variable is set
2-
ansible.builtin.fail:
3-
msg: "INDEX_IMAGE: '{{ iib_image }}' is not set"
4-
failed_when:
5-
(iib_image is not defined or iib_image | length == 0)
6-
71
- name: Check for pre-requisite binaries presence
82
ansible.builtin.shell: |
93
which "{{ item }}"
@@ -12,13 +6,11 @@
126
- oc
137
- podman
148

15-
- name: Set IIB fact
16-
ansible.builtin.set_fact:
17-
iib: "{{ iib_image.split(':')[1] }}"
18-
19-
- name: Set IIB local folder fact
20-
ansible.builtin.set_fact:
21-
iib_local_folder: "/tmp/manifest-{{ iib }}"
9+
- name: Check that INDEX_IMAGES env variable is set
10+
ansible.builtin.fail:
11+
msg: "INDEX_IMAGES: '{{ iib_images }}' is not set"
12+
failed_when:
13+
(iib_images is not defined or iib_images | length == 0)
2214

2315
- name: Get cluster version
2416
# E.g. 4.13.0-rc.6 or 4.12.16
@@ -36,14 +28,44 @@
3628
msg: "OCP versions < 4.13 are not support for IIB loading"
3729
when: not ocp_413
3830

31+
- name: Set images array
32+
ansible.builtin.set_fact:
33+
iib_image_list: "{{ iib_images.split(',') }}"
34+
35+
- name: Set operator array
36+
ansible.builtin.set_fact:
37+
operator_list: "{{ operator.split(',') }}"
38+
39+
# Creates a dict like:
40+
# "advanced-cluster-management": {
41+
# "iib": "713808",
42+
# "iib_image": "registry-proxy.engineering.redhat.com/rh-osbs/iib:713808"
43+
# },
44+
# "multicluster-engine": {
45+
# "iib": "713809",
46+
# "iib_image": "registry-proxy.engineering.redhat.com/rh-osbs/iib:713809"
47+
# }
48+
- name: Set IIB dict
49+
ansible.builtin.set_fact:
50+
iib_dict: "{{ iib_dict | default({}) | combine({item.0: {'iib_image': item.1, 'iib': item.1.split(':')[-1]}}) }}"
51+
with_together:
52+
- "{{ operator_list }}"
53+
- "{{ iib_image_list }}"
54+
55+
- name: Working with the following IIB data
56+
ansible.builtin.debug:
57+
msg: "{{ iib_dict }}"
58+
3959
- name: Set up internal registry (OCP >= 4.13)
4060
ansible.builtin.include_tasks: setup-internal-registry.yml
4161

4262
- name: Install new IIB in cluster
4363
ansible.builtin.include_tasks: install-iib-in-cluster.yml
64+
with_items: "{{ iib_dict | dict2items }}"
4465

4566
- name: Mirror all related images
4667
ansible.builtin.include_tasks: mirror-related-images.yml
68+
with_items: "{{ iib_dict | dict2items }}"
4769

4870
- name: Remove pullsecrets tempfolder
4971
ansible.builtin.file:

ansible/roles/iib_ci/tasks/mirror-related-images.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
# This is needed because some operators like "advanced-cluster-management"
2-
# install a second operator "multicluster-engine"
3-
- name: Set operators list
1+
# We redefine this var so it is easier to run this task independently
2+
- name: Set IIB local folder fact
43
ansible.builtin.set_fact:
5-
operator_list: "{{ [operator] + (operator == 'advanced-cluster-management') | ternary(['multicluster-engine'], []) }}"
4+
iib_local_folder: "/tmp/manifest-{{ item.value['iib'] }}"
65

76
- name: Set all images to empty list
87
ansible.builtin.set_fact:
98
all_images: []
109

1110
- name: Fetch operator images tasks
1211
ansible.builtin.include_tasks: fetch-operator-images.yml
13-
loop: "{{ operator_list }}"
1412

1513
- name: Print all_images
1614
ansible.builtin.debug:
@@ -119,7 +117,7 @@
119117
ansible.builtin.debug:
120118
msg: "{{ image_urls }}"
121119

122-
# OCP 4.13 uses the new fangled "ImageDigestMirrorSet", older OCPs use "ImageContentSourcePolicy"
120+
# OCP 4.13 uses the new fangled "ImageDigestMirrorSet"
123121
- name: Template out imageMirror.yaml (OCP >= 4.13)
124122
ansible.builtin.template:
125123
src: ./templates/imageDigestMirror.yaml.j2
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
apiVersion: operators.coreos.com/v1alpha1
22
kind: CatalogSource
33
metadata:
4-
name: iib-{{ iib }}
4+
name: iib-{{ item.value['iib'] }}
55
namespace: {{ internal_registry_ns }}
66
spec:
7-
image: {{ mirror_iib }}:{{ iib }}
7+
image: {{ mirror_iib }}:{{ item.value['iib'] }}
88
sourceType: grpc
9-
displayName: IIB {{ iib }}
9+
displayName: IIB {{ item.value['iib'] }}

ansible/roles/iib_ci/templates/imageDigestMirror.yaml.j2

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ kind: ImageDigestMirrorSet
33
metadata:
44
labels:
55
operators.openshift.org/catalog: "true"
6-
name: iib-{{ iib }}
6+
name: iib-{{ item.value['iib'] }}
77
spec:
88
imageDigestMirrors:
9-
{% for item in image_urls.values() %}
9+
{% for data in image_urls.values() %}
1010
- mirrors:
11-
- {{ item.mirrordest_nosha }}
12-
source: {{ item.source_nosha }}
11+
- {{ data.mirrordest_nosha }}
12+
source: {{ data.source_nosha }}
1313
mirrorSourcePolicy: AllowContactingSource
1414
- mirrors:
15-
- {{ item.mirrordest_nosha }}
16-
source: {{ item.image_nosha }}
15+
- {{ data.mirrordest_nosha }}
16+
source: {{ data.image_nosha }}
1717
mirrorSourcePolicy: AllowContactingSource
1818
{% endfor %}

0 commit comments

Comments
 (0)