Skip to content

Commit d36afde

Browse files
committed
Allow to prune operators from different catalogs
1 parent 668bf3e commit d36afde

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

roles/prune_catalog/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,35 @@ Another example of a pruned catalog with specific channels
106106
```
107107
108108
In this example, the resulting catalog contains all the channels of the `compliance-operator`, channel `stable-5.8` for cluster-logging and only the `stable` channel for `file-integrity-operator`.
109+
110+
### Prune operators from multiple source catalogs
111+
112+
The role supports pruning operators from multiple source catalogs into a single destination catalog. This is useful when you need operators from different catalog sources (e.g., Red Hat operators, certified operators, community operators).
113+
114+
```yaml
115+
- name: "Create a pruned catalog with operators from multiple catalogs"
116+
include_role:
117+
name: redhatci.ocp.prune_catalog
118+
vars:
119+
pc_source_catalog: "registry.redhat.io/redhat/redhat-operator-index:v4.19"
120+
pc_destination_catalog: "<my-local-registry>:4443/pruned-catalog:latest"
121+
pc_operators:
122+
compliance-operator:
123+
channel: stable
124+
file-integrity-operator:
125+
channel: stable
126+
catalog: "registry.redhat.io/redhat/certified-operator-index:v4.19"
127+
ocs-operator:
128+
channel: stable-4.13
129+
catalog: "registry.redhat.io/redhat/redhat-operator-index:v4.19"
130+
prometheus:
131+
channel: beta
132+
catalog: "registry.redhat.io/redhat/community-operator-index:v4.19"
133+
pc_opm_args: "--skip-tls-verify=true"
134+
```
135+
136+
- Operators without a `catalog` field use the `pc_source_catalog`
137+
109138
```ShellSession
110139
$ DOCKER_CONFIG=/home/<user>/.docker oc-mirror list operators --catalog <my-local-registry>:4443/pruned-catalog:latest
111140
NAME DISPLAY NAME DEFAULT CHANNEL

roles/prune_catalog/tasks/main.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,37 @@
8181
retries: 3
8282
delay: 10
8383

84+
- name: "Render additional catalogs"
85+
vars:
86+
extra_catalogs: >-
87+
{{
88+
(pc_operators | type_debug == "dict") |
89+
ternary(
90+
pc_operators | dict2items |
91+
selectattr('value.catalog', 'defined') |
92+
map(attribute='value.catalog') |
93+
list | unique |
94+
difference([pc_source_catalog]),
95+
[]
96+
)
97+
}}
98+
ansible.builtin.shell:
99+
chdir: "{{ pc_tmp_dir }}"
100+
cmd: >
101+
set -x;
102+
{{ pc_opm_cmd }} render {{ catalog }} >>
103+
index-packages
104+
loop: "{{ extra_catalogs }}"
105+
loop_control:
106+
loop_var: catalog
107+
register: _pc_render_additional
108+
changed_when: _pc_render_additional.rc == 0
109+
until: _pc_render_additional.rc == 0
110+
retries: 3
111+
delay: 10
112+
when:
113+
- extra_catalogs | length > 0
114+
84115
- name: "Extract the listed channels for each operator"
85116
when: pc_operators | type_debug == "dict"
86117
block:

0 commit comments

Comments
 (0)