Skip to content

Commit e8789e1

Browse files
Add resolve_image_pullspecs customization for pinning
Refers to CLOUDDST-10231
1 parent aa3becf commit e8789e1

4 files changed

Lines changed: 21 additions & 26 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,18 @@ The custom configuration options for the Celery workers are listed below:
303303
organization, the `related_bundles` endpoint won't work for regenerate-bundle requests of that
304304
organization. If no organization is specified, IIB will try to find `related_bundles` for all
305305
regenerate-bundle requests.
306+
* The `resolve_image_pullspecs` customization type is a dictionary with no additional arguments
307+
and it basically pins all the pull specs in the CSV files of the operator bundle image in
308+
question to their digests. If this customization is not specified in the config for an
309+
organization, the pinning will not be done. If no organization is specified, IIB will try and
310+
pin the pull specs in the CSV files to their digests.
306311

307312
Here is an example that ties this all together:
308313

309314
```python
310315
iib_organization_customizations = {
311316
'company-marketplace': [
317+
{'type': 'resolve_image_pullspecs'},
312318
{
313319
'type': 'csv_annotations',
314320
'annotations': {

iib/workers/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class DevelopmentConfig(Config):
7373
iib_log_level = 'DEBUG'
7474
iib_organization_customizations = {
7575
'company-marketplace': [
76+
{'type': 'resolve_image_pullspecs'},
7677
{'type': 'related_bundles'},
7778
{
7879
'type': 'csv_annotations',

iib/workers/tasks/build_regenerate_bundle.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def _adjust_operator_bundle(
221221
organization_customizations = conf['iib_organization_customizations'].get(organization, [])
222222
if not organization_customizations:
223223
organization_customizations = [
224+
{'type': 'resolve_image_pullspecs'},
224225
{'type': 'related_bundles'},
225226
{'type': 'package_name_suffix'},
226227
{'type': 'registry_replacements'},
@@ -235,10 +236,6 @@ def _adjust_operator_bundle(
235236
]
236237
labels = {}
237238

238-
log.info('Resolving image pull specs')
239-
bundle_metadata = _get_bundle_metadata(operator_manifest, pinned_by_iib)
240-
_resolve_image_pull_specs(bundle_metadata, labels, pinned_by_iib)
241-
242239
# Perform the customizations in order
243240
for customization in organization_customizations:
244241
customization_type = customization['type']
@@ -285,6 +282,10 @@ def _adjust_operator_bundle(
285282
log.info('Applying related_bundles customization')
286283
bundle_metadata = _get_bundle_metadata(operator_manifest, pinned_by_iib)
287284
_write_related_bundles_file(bundle_metadata, request_id)
285+
elif customization_type == 'resolve_image_pullspecs':
286+
log.info('Resolving image pull specs')
287+
bundle_metadata = _get_bundle_metadata(operator_manifest, pinned_by_iib)
288+
_resolve_image_pull_specs(bundle_metadata, labels, pinned_by_iib)
288289

289290
return labels
290291

tests/test_workers/test_tasks/test_build_regenerate_bundle.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -978,13 +978,13 @@ def test_apply_repo_enclosure(original_image, eclosure_namespace, expected_image
978978
@mock.patch('iib.workers.tasks.build_regenerate_bundle._adjust_csv_annotations')
979979
@mock.patch('iib.workers.tasks.build_regenerate_bundle.get_image_labels')
980980
@mock.patch('iib.workers.tasks.build_regenerate_bundle._write_related_bundles_file')
981+
@mock.patch('iib.workers.tasks.build_regenerate_bundle._resolve_image_pull_specs')
981982
def test_adjust_operator_bundle_duplicate_customizations_ordered(
982-
mock_grbi, mock_gil, mock_aca, mock_gri, mock_apns, mock_gpa, tmpdir
983+
mock_rips, mock_grbi, mock_gil, mock_aca, mock_gri, mock_apns, mock_gpa, tmpdir
983984
):
984985
manager = MagicMock()
985986
manager.attach_mock(mock_gpa, 'mock_gpa')
986987
manager.attach_mock(mock_apns, 'mock_apns')
987-
manager.attach_mock(mock_gri, 'mock_gri')
988988
manager.attach_mock(mock_aca, 'mock_aca')
989989
manager.attach_mock(mock_gil, 'mock_gil')
990990
manager.attach_mock(mock_grbi, 'mock_grbi')
@@ -1042,7 +1042,7 @@ def test_adjust_operator_bundle_duplicate_customizations_ordered(
10421042
registry='quay.io',
10431043
operator='operator',
10441044
image='/image',
1045-
ref=':v1',
1045+
ref='@sha256:654322',
10461046
related_name=f'image-{image_digest}-annotation',
10471047
related_ref='@sha256:749327',
10481048
)
@@ -1054,29 +1054,18 @@ def test_adjust_operator_bundle_duplicate_customizations_ordered(
10541054
)
10551055
csv3.write(
10561056
csv_template.format(
1057-
registry='registry.access.company.com', operator='operator', image='/image', ref=':v2'
1057+
registry='registry.access.company.com',
1058+
operator='operator',
1059+
image='/image',
1060+
ref='@sha256:654321',
10581061
)
10591062
)
10601063

1061-
def get_resolved_image(image):
1062-
return {
1063-
'quay.io/operator/image:v1': 'quay.io/operator/image@sha256:654322',
1064-
'quay.io/operator/image:v2': 'quay.io/operator/image@sha256:654321',
1065-
'quay.io/operator/image@sha256:654321': 'quay.io/operator/image@sha256:654321',
1066-
'quay.io/operator/image@sha256:749327': 'quay.io/operator/image@sha256:749327',
1067-
'registry.access.company.com/operator/image:v2': (
1068-
'registry.access.company.com/operator/image@sha256:654321'
1069-
),
1070-
}[image]
1071-
1072-
mock_gri.side_effect = get_resolved_image
1073-
10741064
labels = build_regenerate_bundle._adjust_operator_bundle(
10751065
str(manifests_dir), str(metadata_dir), 1, 'company-managed'
10761066
)
10771067

10781068
assert labels == {
1079-
'com.redhat.iib.pinned': 'true',
10801069
'operators.operatorframework.io.bundle.package.v1': 'amqstreams-cmp',
10811070
}
10821071
# Verify that the relatedImages are not modified if they were already set and that images were
@@ -1110,10 +1099,6 @@ def get_resolved_image(image):
11101099

11111100
expected_calls = [
11121101
call.mock_gpa(mock.ANY),
1113-
call.mock_gri(mock.ANY),
1114-
call.mock_gri(mock.ANY),
1115-
call.mock_gri(mock.ANY),
1116-
call.mock_gri(mock.ANY),
11171102
call.mock_apns(mock.ANY, '-cmp'),
11181103
call.mock_aca(mock.ANY, 'amqstreams', annotations),
11191104
call.mock_grbi(mock.ANY, 1),
@@ -1122,6 +1107,8 @@ def get_resolved_image(image):
11221107
call.mock_gil(mock.ANY),
11231108
]
11241109
assert manager.mock_calls == expected_calls
1110+
mock_rips.assert_not_called()
1111+
mock_gri.assert_not_called()
11251112

11261113

11271114
@mock.patch('iib.workers.tasks.build_regenerate_bundle.get_image_label')

0 commit comments

Comments
 (0)