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

IIB uses opm render #784

Merged
merged 3 commits into from
Feb 5, 2025
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
24 changes: 7 additions & 17 deletions iib/workers/tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from iib.workers.greenwave import gate_bundles
from iib.workers.tasks.fbc_utils import is_image_fbc, get_catalog_dir, merge_catalogs_dirs
from iib.workers.tasks.opm_operations import (
opm_serve_from_index,
opm_registry_add_fbc,
opm_migrate,
opm_registry_rm_fbc,
Expand All @@ -40,12 +39,12 @@
verify_operators_exists,
create_dockerfile,
opm_validate,
get_list_bundles,
)
from iib.workers.tasks.utils import (
add_max_ocp_version_property,
chmod_recursively,
get_bundles_from_deprecation_list,
get_bundle_json,
get_resolved_bundles,
get_resolved_image,
podman_pull,
Expand All @@ -58,7 +57,6 @@
get_image_label,
verify_labels,
prepare_request_for_build,
terminate_process,
get_bundle_metadata,
)
from iib.workers.tasks.iib_static_types import (
Expand Down Expand Up @@ -392,22 +390,14 @@ def _get_present_bundles(from_index: str, base_dir: str) -> Tuple[List[BundleIma
:rtype: list, list
:raises IIBError: if any of the commands fail.
"""
port, rpc_proc = opm_serve_from_index(base_dir, from_index=from_index)

bundles = run_cmd(
['grpcurl', '-plaintext', f'localhost:{port}', 'api.Registry/ListBundles'],
exc_msg='Failed to get bundle data from index image',
)
terminate_process(rpc_proc)

# If no data is returned there are not bundles present
if not bundles:
return [], []

# Transform returned data to parsable json
# Get list of bundles
unique_present_bundles: List[BundleImage] = []
unique_present_bundles_pull_spec: List[str] = []
present_bundles: List[BundleImage] = get_bundle_json(bundles)
present_bundles: List[BundleImage] = get_list_bundles(from_index, base_dir)

# If no data is returned there are no bundles present
if not present_bundles:
return [], []

for bundle in present_bundles:
bundle_path = bundle['bundlePath']
Expand Down
39 changes: 8 additions & 31 deletions iib/workers/tasks/build_create_empty_index.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import tempfile
import json
import re
from typing import Dict, List, Optional
from typing import Dict, Optional

from iib.common.tracing import instrument_tracing
from iib.exceptions import IIBError
Expand All @@ -20,12 +18,16 @@
)
from iib.workers.tasks.celery import app
from iib.workers.tasks.fbc_utils import is_image_fbc
from iib.workers.tasks.opm_operations import opm_create_empty_fbc, opm_index_rm, Opm
from iib.workers.tasks.opm_operations import (
opm_create_empty_fbc,
opm_index_rm,
Opm,
get_operator_package_list,
)
from iib.workers.tasks.utils import (
request_logger,
prepare_request_for_build,
RequestConfigCreateIndexImage,
grpcurl_get_db_data,
)
from iib.workers.tasks.iib_static_types import PrebuildInfo

Expand All @@ -34,31 +36,6 @@
log = logging.getLogger(__name__)


def _get_present_operators(from_index: str, base_dir: str) -> List[str]:
"""Get a list of operators already present in the index image.

:param str from_index: index image to inspect.
:param str base_dir: base directory to create temporary files in.
:return: list of unique present operators as provided by the grpc query
:rtype: list
:raises IIBError: if any of the commands fail.
"""
operators = grpcurl_get_db_data(from_index, base_dir, "api.Registry/ListPackages")

# If no data is returned there are not operators present
if not operators:
return []

# Transform returned data to parsable json
present_operators = []
new_operators = [json.loads(operator) for operator in re.split(r'(?<=})\n(?={)', operators)]

for operator in new_operators:
present_operators.append(operator['name'])

return present_operators


@app.task
@request_logger
@instrument_tracing(
Expand Down Expand Up @@ -108,7 +85,7 @@ def handle_create_empty_index_request(
with tempfile.TemporaryDirectory(prefix=f'iib-{request_id}-') as temp_dir:
set_request_state(request_id, 'in_progress', 'Checking operators present in index image')

operators = _get_present_operators(from_index_resolved, temp_dir)
operators = get_operator_package_list(from_index_resolved, temp_dir)

# if output_fbc parameter is true, create an empty FBC index image
# else create empty SQLite index image
Expand Down
Loading