Example #1
0
def get_legacy_support_packages(bundles,
                                request_id,
                                ocp_version,
                                force_backport=False):
    """
    Get the packages that must be pushed to the legacy application registry.

    :param list<str> bundles: a list of strings representing the pull specifications of the bundles
        to add to the index image being built.
    :param int request_id: the ID of the IIB build request.
    :param str ocp_version: the OCP version that the index is intended for.
    :param bool force_backport: if True, backport legacy support is forced for every package
    :return: a set of packages that require legacy support
    :rtype: set
    """
    packages = set()
    if ocp_version != 'v4.5':
        log.info('Backport legacy support is disabled for %s', ocp_version)
        return packages
    if force_backport:
        set_request_state(request_id, 'in_progress',
                          'Backport legacy support will be forced')
    for bundle in bundles:
        labels = get_image_labels(bundle)
        if force_backport or ruamel.yaml.safe_load(
                labels.get('com.redhat.delivery.backport', 'false')):
            packages.add(
                labels['operators.operatorframework.io.bundle.package.v1'])

    return packages
Example #2
0
def _replace_image_name_from_labels(bundle_metadata, replacement_template):
    """
    Replace repo/image-name in the CSV pull specs with values from their labels.

    :param dict bundle_metadata: the dictionary of CSV's and relatedImages pull specifications
    :param str replacement_template: the template specifying which label values to use for
        replacement
    """
    replacement_pullspecs = {}

    for pullspec in bundle_metadata['found_pullspecs']:
        new_pullspec = ImageName.parse(pullspec.to_str())
        pullspec_labels = get_image_labels(pullspec.to_str())
        try:
            modified_namespace_repo = replacement_template.format(**pullspec_labels)
        except KeyError:
            raise IIBError(
                f'Pull spec {pullspec.to_str()} is missing one or more label(s)'
                f' required in the image_name_from_labels {replacement_template}.'
                f' Available labels: {", ".join(list(pullspec_labels.keys()))}'
            )

        namespace_repo_list = modified_namespace_repo.split('/', 1)
        if len(namespace_repo_list) == 1:
            namespace_repo_list.insert(0, None)

        new_pullspec.namespace, new_pullspec.repo = namespace_repo_list
        replacement_pullspecs[pullspec] = new_pullspec

    # Related images have already been set when resolving pull_specs.
    _replace_csv_pullspecs(bundle_metadata, replacement_pullspecs)
Example #3
0
def get_image_label(pull_spec, label):
    """
    Get a specific label from the container image.

    :param str label: the label to get
    :return: the label on the container image or None
    :rtype: str
    """
    log.debug('Getting the label of %s from %s', label, pull_spec)
    return get_image_labels(pull_spec).get(label)
Example #4
0
def _get_koji_build_nvr(bundle):
    """
    Get the Koji build NVR of the bundle from its labels.

    :param str bundle: the pull specification of the bundle image to be gated.
    :return: the Koji build NVR of the bundle image.
    :rtype: str
    """
    labels = get_image_labels(bundle)
    return '{}-{}-{}'.format(labels['com.redhat.component'], labels['version'], labels['release'])
Example #5
0
File: legacy.py Project: lcarva/iib
def get_legacy_support_packages(bundles):
    """
    Get the packages that must be pushed to the legacy application registry.

    :param list<str> bundles: a list of strings representing the pull specifications of the bundles
        to add to the index image being built.
    :return: a set of packages that require legacy support
    :rtype: set
    """
    packages = set()
    for bundle in bundles:
        labels = get_image_labels(bundle)
        if labels.get('com.redhat.delivery.backport', False):
            packages.add(
                labels['operators.operatorframework.io.bundle.package.v1'])

    return packages
Example #6
0
def _verify_labels(bundles):
    """
    Verify that the required labels are set on the input bundles.

    :param list bundles: a list of strings representing the pull specifications of the bundles to
        add to the index image being built.
    :raises IIBError: if one of the bundles does not have the correct label value.
    """
    conf = get_worker_config()
    if not conf['iib_required_labels']:
        return

    for bundle in bundles:
        labels = get_image_labels(bundle)
        for label, value in conf['iib_required_labels'].items():
            if labels.get(label) != value:
                raise IIBError(
                    f'The bundle {bundle} does not have the label {label}={value}'
                )
Example #7
0
def get_legacy_support_packages(bundles, request_id, force_backport=False):
    """
    Get the packages that must be pushed to the legacy application registry.

    :param list<str> bundles: a list of strings representing the pull specifications of the bundles
        to add to the index image being built.
    :param int request_id: the ID of the IIB build request.
    :param bool force_backport: if True, backport legacy support is forced for every package
    :return: a set of packages that require legacy support
    :rtype: set
    """
    if force_backport:
        set_request_state(request_id, 'in_progress',
                          'Backport legacy support will be forced')
    packages = set()
    for bundle in bundles:
        labels = get_image_labels(bundle)
        if force_backport or labels.get('com.redhat.delivery.backport', False):
            packages.add(
                labels['operators.operatorframework.io.bundle.package.v1'])

    return packages
Example #8
0
def test_get_image_labels(mock_si):
    skopeo_rv = {'config': {'Labels': {'some_label': 'value'}}}
    mock_si.return_value = skopeo_rv
    assert utils.get_image_labels(
        'some-image:latest') == skopeo_rv['config']['Labels']