1
0
Fork 0

Allow listing available checks from cli

This commit is contained in:
Maurizio Porrato 2023-08-08 09:06:11 +01:00
parent aefe6d2abe
commit 9f91b8608a
4 changed files with 26 additions and 2 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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()

View File

@ -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]