Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing deprecation of operator in FBC image #520

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions iib/workers/tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion: This could be deprecate_bundle_package

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)
lipoja marked this conversation as resolved.
Show resolved Hide resolved

# 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)
Expand Down
4 changes: 2 additions & 2 deletions iib/workers/tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workers/test_tasks/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}}
Expand Down