From 745cf02050b1998e8f665a0646fbd41a047dd628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lipovsk=C3=BD?= Date: Thu, 8 Jun 2023 15:25:45 +0200 Subject: [PATCH 1/2] Fixing deprecation of operator in FBC image CLOUDDST-19095 --- iib/workers/tasks/build.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/iib/workers/tasks/build.py b/iib/workers/tasks/build.py index 9325cdf9..8bcd5522 100644 --- a/iib/workers/tasks/build.py +++ b/iib/workers/tasks/build.py @@ -972,6 +972,24 @@ def handle_add_request( catalog_from_index = get_catalog_dir( from_index=from_index_resolved, base_dir=os.path.join(temp_dir, 'from_index') ) + + # we have to remove all `deprecation_bundles` from `catalog_from_index` + # before merging catalogs otherwise if catalog was deprecated and + # removed from `index.db` it stays on FBC (from_index) + # Therefore we have to remove the directory before merging + for deprecate_bundle_pull_spec in deprecation_bundles: + # remove deprecated operators from FBC stored in index image + deprecate_bundle = get_image_label( + deprecate_bundle_pull_spec, 'operators.operatorframework.io.bundle.package.v1' + ) + bundle_from_index = os.path.join(catalog_from_index, deprecate_bundle) + if os.path.exists(bundle_from_index): + log.debug( + "Removing deprecated bundle from catalog before merging: %s", + deprecate_bundle, + ) + shutil.rmtree(bundle_from_index) + # overwrite data in `catalog_from_index` by data from `catalog_from_db` # this adds changes on not opted in operators to final merge_catalogs_dirs(catalog_from_db, catalog_from_index) From 9415964d9aab6db7537de14fb39df94198a84687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lipovsk=C3=BD?= Date: Mon, 12 Jun 2023 15:50:17 +0200 Subject: [PATCH 2/2] Update get_image_label return value --- iib/workers/tasks/utils.py | 4 ++-- tests/test_workers/test_tasks/test_utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iib/workers/tasks/utils.py b/iib/workers/tasks/utils.py index c0e4a406..fbd6bb6e 100644 --- a/iib/workers/tasks/utils.py +++ b/iib/workers/tasks/utils.py @@ -1088,7 +1088,7 @@ def get_all_index_images_info( return infos -def get_image_label(pull_spec: str, label: str) -> Optional[str]: +def get_image_label(pull_spec: str, label: str) -> str: """ Get a specific label from the container image. @@ -1098,7 +1098,7 @@ def get_image_label(pull_spec: str, label: str) -> Optional[str]: :rtype: str """ log.debug('Getting the label of %s from %s', label, pull_spec) - return get_image_labels(pull_spec).get(label) + return get_image_labels(pull_spec).get(label, '') def verify_labels(bundles: List[str]) -> None: diff --git a/tests/test_workers/test_tasks/test_utils.py b/tests/test_workers/test_tasks/test_utils.py index 7f3ca302..256fc7f1 100644 --- a/tests/test_workers/test_tasks/test_utils.py +++ b/tests/test_workers/test_tasks/test_utils.py @@ -795,7 +795,7 @@ def test_get_image_arches_not_manifest_list(mock_si): utils.get_image_arches('image:latest') -@pytest.mark.parametrize('label, expected', (('some_label', 'value'), ('not_there', None))) +@pytest.mark.parametrize('label, expected', (('some_label', 'value'), ('not_there', ''))) @mock.patch('iib.workers.tasks.utils.skopeo_inspect') def test_get_image_label(mock_si, label, expected): mock_si.return_value = {'config': {'Labels': {'some_label': 'value'}}}