Skip to content

Commit

Permalink
[ISV-5374] Add check to suggest FBC for non-FBC operators (#744)
Browse files Browse the repository at this point in the history
* [ISV-5374] Add check to suggest FBC for non-FBC operators
  • Loading branch information
mantomas authored Oct 30, 2024
1 parent aea3647 commit e790e2d
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,44 @@ def check_replaces_availability(bundle: Bundle) -> Iterator[CheckResult]:
f"`{replaces_bundle}` - `{replaces_ocp_version_str}`"
)
yield from []


NON_FBC_SUGGESTION = (
"[File Based Catalog (FBC)]"
"(https://github.com/redhat-openshift-ecosystem/community-operators-prod/"
"discussions/5031#discussion-7097441) "
"is a new way to manage operator metadata. "
"This operator does not use FBC. Consider [migrating]"
"(https://redhat-openshift-ecosystem.github.io/operator-pipelines/users/fbc_onboarding/) "
"for better maintainability."
)
NON_FBC_WARNING = (
"[File Based Catalog (FBC)]"
"(https://github.com/redhat-openshift-ecosystem/community-operators-prod/"
"discussions/5031#discussion-7097441) "
"is a new way to manage operator metadata. "
"This operator does not use FBC and it is recommended for new operators to "
"[start directly with FBC]"
"(https://redhat-openshift-ecosystem.github.io/operator-pipelines/users/fbc_workflow/). "
"The use of FBC will be mandatory for new operators from February 2025."
)


@skip_fbc
def check_using_fbc(bundle: Bundle) -> Iterator[CheckResult]:
"""
This check is used only for non-FBC bundles and suggests
using the File Based Catalog for new Operators
or recommends migrating existing Operators to FBC.
Args:
bundle (Bundle): Tested operator bundle
"""
all_bundles = set(bundle.operator.all_bundles())
other_bundles = all_bundles - {bundle}
if other_bundles:
# not a first bundle, existing operator
yield Warn(NON_FBC_SUGGESTION)
else:
# TODO: change to Fail when FBC mandatory for new operators
yield Warn(NON_FBC_WARNING)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
check_api_version_constraints,
check_replaces_availability,
check_upgrade_graph_loop,
check_using_fbc,
ocp_to_k8s_ver,
)
from semver import Version
Expand Down Expand Up @@ -673,3 +674,43 @@ def test_check_replaces_availability(
errors = list(check_replaces_availability(bundle))

assert set(errors) == expected


@pytest.mark.parametrize(
"files, bundle_to_check, expected",
[
pytest.param(
[
bundle_files("hello", "0.0.1"),
],
("hello", "0.0.1"),
"is recommended for new operators",
id="New bundle warning",
),
pytest.param(
[
bundle_files("hello", "0.0.1"),
bundle_files("hello", "0.0.2"),
],
("hello", "0.0.2"),
"This operator does not use FBC. Consider",
id="Updating existing operator",
),
],
)
def test_using_fbc(
tmp_path: Path,
files: list[dict[str, Any]],
bundle_to_check: tuple[str, str],
expected: str,
) -> None:
create_files(tmp_path, *files)
repo = Repo(tmp_path)
operator_name, bundle_version = bundle_to_check
operator = repo.operator(operator_name)
bundle = operator.bundle(bundle_version)

results = list(check_using_fbc(bundle))

assert len(results) == 1
assert expected in results[0].reason
43 changes: 22 additions & 21 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e790e2d

Please sign in to comment.