Keep track of where check results originated from
This commit is contained in:
parent
2997b64eba
commit
8d5fde5fcd
|
@ -1,23 +1,26 @@
|
|||
import importlib
|
||||
from collections.abc import Callable, Iterable, Mapping
|
||||
from inspect import getmembers, isfunction
|
||||
from typing import Union
|
||||
|
||||
from .. import Bundle, Operator
|
||||
from .. import Bundle, Operator, Repo
|
||||
|
||||
|
||||
class CheckResult:
|
||||
severity: int = 0
|
||||
display: str = "UNKNOWN"
|
||||
origin: Union[Repo, Operator, Bundle, None]
|
||||
reason: str
|
||||
|
||||
def __init__(self, reason: str):
|
||||
def __init__(self, origin, reason: str):
|
||||
self.origin = origin
|
||||
self.reason = reason
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.display}: {self.reason}"
|
||||
return f"{self.display}: {self.origin}: {self.reason}"
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.display}({self.reason})"
|
||||
return f"{self.display}({self.origin}, {self.reason})"
|
||||
|
||||
def __int__(self):
|
||||
return self.severity
|
||||
|
|
|
@ -15,11 +15,13 @@ def check_operator_name(bundle: Bundle) -> Iterator[CheckResult]:
|
|||
return
|
||||
if name != bundle.csv_operator_name:
|
||||
yield Fail(
|
||||
f"Operator name from annotations.yaml ({name}) does not match the name defined in the CSV ({bundle.csv_operator_name})"
|
||||
bundle,
|
||||
f"Operator name from annotations.yaml ({name}) does not match the name defined in the CSV ({bundle.csv_operator_name})",
|
||||
)
|
||||
if name != bundle.operator_name:
|
||||
yield Fail(
|
||||
f"Operator name from annotations.yaml ({name}) does not match the operator's directory name ({bundle.operator_name})"
|
||||
bundle,
|
||||
f"Operator name from annotations.yaml ({name}) does not match the operator's directory name ({bundle.operator_name})",
|
||||
)
|
||||
|
||||
|
||||
|
@ -28,19 +30,23 @@ def check_image(bundle: Bundle) -> Iterator[CheckResult]:
|
|||
try:
|
||||
container_image = lookup_dict(bundle.csv, "metadata.annotations.containerImage")
|
||||
if container_image is None:
|
||||
yield Fail(f"CSV doesn't define .metadata.annotations.containerImage")
|
||||
yield Fail(
|
||||
bundle, f"CSV doesn't define .metadata.annotations.containerImage"
|
||||
)
|
||||
return
|
||||
deployments = lookup_dict(bundle.csv, "spec.install.spec.deployments")
|
||||
if deployments is None:
|
||||
yield Fail(f"CSV doesn't define .spec.install.spec.deployments")
|
||||
yield Fail(bundle, f"CSV doesn't define .spec.install.spec.deployments")
|
||||
return
|
||||
for deployment in deployments:
|
||||
containers = lookup_dict(deployment, "spec.template.spec.containers", [])
|
||||
if any(container_image == x.get("image") for x in containers):
|
||||
return
|
||||
yield Fail(f"container image {container_image} not used by any deployment")
|
||||
yield Fail(
|
||||
bundle, f"container image {container_image} not used by any deployment"
|
||||
)
|
||||
except Exception as e:
|
||||
yield Fail(str(e))
|
||||
yield Fail(bundle, str(e))
|
||||
|
||||
|
||||
def check_semver(bundle: Bundle) -> Iterator[CheckResult]:
|
||||
|
@ -49,11 +55,13 @@ def check_semver(bundle: Bundle) -> Iterator[CheckResult]:
|
|||
_ = Version.parse(bundle.operator_version)
|
||||
except ValueError:
|
||||
yield Warn(
|
||||
f"Version from filesystem ({bundle.operator_version}) is not valid semver"
|
||||
bundle,
|
||||
f"Version from filesystem ({bundle.operator_version}) is not valid semver",
|
||||
)
|
||||
try:
|
||||
_ = Version.parse(bundle.csv_operator_version)
|
||||
except ValueError:
|
||||
yield Warn(
|
||||
f"Version from CSV ({bundle.csv_operator_version}) is not valid semver"
|
||||
bundle,
|
||||
f"Version from CSV ({bundle.csv_operator_version}) is not valid semver",
|
||||
)
|
||||
|
|
|
@ -17,7 +17,8 @@ def check_upgrade(operator: Operator) -> Iterator[CheckResult]:
|
|||
}
|
||||
if dangling_bundles:
|
||||
yield Fail(
|
||||
f"Channel {channel} has dangling bundles: {dangling_bundles}."
|
||||
operator,
|
||||
f"Channel {channel} has dangling bundles: {dangling_bundles}.",
|
||||
)
|
||||
except Exception as exc:
|
||||
yield Fail(f"{operator}: {exc}")
|
||||
yield Fail(operator, str(exc))
|
||||
|
|
Loading…
Reference in New Issue