diff --git a/src/operator_repo/checks/bundle.py b/src/operator_repo/checks/bundle.py index f342ecc..a1c9ff0 100644 --- a/src/operator_repo/checks/bundle.py +++ b/src/operator_repo/checks/bundle.py @@ -7,6 +7,7 @@ from ..utils import lookup_dict def check_operator_name(bundle: Bundle) -> Iterator[Tuple[str, str]]: + """Check if the operator names used in CSV, metadata and filesystem are consistent""" name = bundle.annotations.get("operators.operatorframework.io.bundle.package.v1") if name is None: yield "fail", "Bundle does not define the operator name in annotations.yaml" @@ -18,6 +19,7 @@ def check_operator_name(bundle: Bundle) -> Iterator[Tuple[str, str]]: def check_image(bundle: Bundle) -> Iterator[Tuple[str, str]]: + """Check if containerImage is properly defined and used in a deployment""" try: container_image = lookup_dict(bundle.csv, "metadata.annotations.containerImage") if container_image is None: @@ -37,6 +39,7 @@ def check_image(bundle: Bundle) -> Iterator[Tuple[str, str]]: def check_semver(bundle: Bundle) -> Iterator[Tuple[str, str]]: + """Check that the bundle version is semver compliant""" try: _ = Version.parse(bundle.operator_version) except ValueError: diff --git a/src/operator_repo/checks/operator.py b/src/operator_repo/checks/operator.py index c8f488c..21a3992 100644 --- a/src/operator_repo/checks/operator.py +++ b/src/operator_repo/checks/operator.py @@ -4,6 +4,7 @@ from .. import Operator def check_upgrade(operator: Operator) -> Iterator[Tuple[str, str]]: + """Validate upgrade graphs for all channels""" all_channels = operator.channels | {operator.default_channel} - {None} for channel in sorted(all_channels): try: diff --git a/src/operator_repo/cli.py b/src/operator_repo/cli.py index 24bfa07..f23c269 100644 --- a/src/operator_repo/cli.py +++ b/src/operator_repo/cli.py @@ -97,6 +97,18 @@ def action_check(repo_path: Path, *what: str, recursive: bool = False) -> None: action_check_bundle(target) +def action_check_list() -> None: + for check_type_name, check_type in ( + ("Operator", operator_checks), + ("Bundle", bundle_checks), + ): + print(f"{check_type_name} checks:") + for check_name, check in getmembers(check_type, isfunction): + if check_name.startswith("check_"): + display_name = check_name.removeprefix("check_") + print(f" - {display_name}: {check.__doc__}") + + def main() -> None: main_parser = argparse.ArgumentParser( description="Operator repository manipulation tool", @@ -127,6 +139,9 @@ def main() -> None: "check", help="check validity of an operator or bundle", ) + check_parser.add_argument( + "--list", action="store_true", help="list available checks" + ) check_parser.add_argument( "-R", "--recursive", action="store_true", help="descend the tree" ) @@ -151,7 +166,12 @@ def main() -> None: if args.action in ("list", "ls"): action_list(args.repo or Path.cwd(), *args.target, recursive=args.recursive) elif args.action == "check": - action_check(args.repo or Path.cwd(), *args.target, recursive=args.recursive) + if args.list: + action_check_list() + else: + action_check( + args.repo or Path.cwd(), *args.target, recursive=args.recursive + ) else: main_parser.print_help() diff --git a/tox.ini b/tox.ini index 2bf3a60..f30d31c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{38,39,310,311}, pypy39 +envlist = py{39,310,311}, pypy39 isolated_build = True ; This is required for a pyproject.toml based project. [testenv]