Skip to content

Commit e790e2d

Browse files
authored
[ISV-5374] Add check to suggest FBC for non-FBC operators (#744)
* [ISV-5374] Add check to suggest FBC for non-FBC operators
1 parent aea3647 commit e790e2d

File tree

3 files changed

+104
-21
lines changed

3 files changed

+104
-21
lines changed

operator-pipeline-images/operatorcert/static_tests/community/bundle.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,44 @@ def check_replaces_availability(bundle: Bundle) -> Iterator[CheckResult]:
441441
f"`{replaces_bundle}` - `{replaces_ocp_version_str}`"
442442
)
443443
yield from []
444+
445+
446+
NON_FBC_SUGGESTION = (
447+
"[File Based Catalog (FBC)]"
448+
"(https://github.com/redhat-openshift-ecosystem/community-operators-prod/"
449+
"discussions/5031#discussion-7097441) "
450+
"is a new way to manage operator metadata. "
451+
"This operator does not use FBC. Consider [migrating]"
452+
"(https://redhat-openshift-ecosystem.github.io/operator-pipelines/users/fbc_onboarding/) "
453+
"for better maintainability."
454+
)
455+
NON_FBC_WARNING = (
456+
"[File Based Catalog (FBC)]"
457+
"(https://github.com/redhat-openshift-ecosystem/community-operators-prod/"
458+
"discussions/5031#discussion-7097441) "
459+
"is a new way to manage operator metadata. "
460+
"This operator does not use FBC and it is recommended for new operators to "
461+
"[start directly with FBC]"
462+
"(https://redhat-openshift-ecosystem.github.io/operator-pipelines/users/fbc_workflow/). "
463+
"The use of FBC will be mandatory for new operators from February 2025."
464+
)
465+
466+
467+
@skip_fbc
468+
def check_using_fbc(bundle: Bundle) -> Iterator[CheckResult]:
469+
"""
470+
This check is used only for non-FBC bundles and suggests
471+
using the File Based Catalog for new Operators
472+
or recommends migrating existing Operators to FBC.
473+
474+
Args:
475+
bundle (Bundle): Tested operator bundle
476+
"""
477+
all_bundles = set(bundle.operator.all_bundles())
478+
other_bundles = all_bundles - {bundle}
479+
if other_bundles:
480+
# not a first bundle, existing operator
481+
yield Warn(NON_FBC_SUGGESTION)
482+
else:
483+
# TODO: change to Fail when FBC mandatory for new operators
484+
yield Warn(NON_FBC_WARNING)

operator-pipeline-images/tests/static_tests/community/test_bundle.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
check_api_version_constraints,
1616
check_replaces_availability,
1717
check_upgrade_graph_loop,
18+
check_using_fbc,
1819
ocp_to_k8s_ver,
1920
)
2021
from semver import Version
@@ -673,3 +674,43 @@ def test_check_replaces_availability(
673674
errors = list(check_replaces_availability(bundle))
674675

675676
assert set(errors) == expected
677+
678+
679+
@pytest.mark.parametrize(
680+
"files, bundle_to_check, expected",
681+
[
682+
pytest.param(
683+
[
684+
bundle_files("hello", "0.0.1"),
685+
],
686+
("hello", "0.0.1"),
687+
"is recommended for new operators",
688+
id="New bundle warning",
689+
),
690+
pytest.param(
691+
[
692+
bundle_files("hello", "0.0.1"),
693+
bundle_files("hello", "0.0.2"),
694+
],
695+
("hello", "0.0.2"),
696+
"This operator does not use FBC. Consider",
697+
id="Updating existing operator",
698+
),
699+
],
700+
)
701+
def test_using_fbc(
702+
tmp_path: Path,
703+
files: list[dict[str, Any]],
704+
bundle_to_check: tuple[str, str],
705+
expected: str,
706+
) -> None:
707+
create_files(tmp_path, *files)
708+
repo = Repo(tmp_path)
709+
operator_name, bundle_version = bundle_to_check
710+
operator = repo.operator(operator_name)
711+
bundle = operator.bundle(bundle_version)
712+
713+
results = list(check_using_fbc(bundle))
714+
715+
assert len(results) == 1
716+
assert expected in results[0].reason

pdm.lock

Lines changed: 22 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)