From eac8cd8ea9f022f000581840bb89660cf8aad333 Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Mon, 11 Dec 2023 12:30:48 +0100 Subject: [PATCH] fix --- lib/check/checkKubernetes.py | 26 +++++++++++++++++++++----- lib/version.py | 2 +- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/check/checkKubernetes.py b/lib/check/checkKubernetes.py index c0abc99..f4ed6f2 100644 --- a/lib/check/checkKubernetes.py +++ b/lib/check/checkKubernetes.py @@ -13,7 +13,11 @@ def is_none(inp: Any): - return inp is None or inp == 'None' + return inp is None or inp == 'None' or inp == '' + + +def is_none_empty_str(inp): + return isinstance(inp, str) and inp != '' def on_node(item) -> dict: @@ -210,19 +214,30 @@ def on_pvc_usage_metrics(item, metrics: dict) -> dict: } +def ensure_list_none_empty_strings(inp): + if is_none(inp): + return [] + if isinstance(inp, str): + return inp.split(',') + if isinstance(inp, (list, tuple)): + return [itm for itm in inp if is_none_empty_str(itm)] + logging.warning(f'Expecting a list of strings but got: {inp}') + return [] + + def svc_external_ips(item) -> dict: spec = item.spec status = item.status if spec.type in ('ClusterIP', 'NodePort'): - return [] if is_none(spec.external_ips) else spec.external_ips + return ensure_list_none_empty_strings(spec.external_ips) elif spec.type == 'LoadBalancer': - ips = [] if is_none(spec.external_ips) else spec.external_ips + ips = ensure_list_none_empty_strings(spec.external_ips) if not is_none(status.load_balancer.ingress): for i in status.load_balancer.ingress: - if i.ip != '': + if is_none_empty_str(i.ip): ips.append(i.ip) - elif i.hostname != '': + elif is_none_empty_str(i.hostname): ips.append(i.hostname) return ips return [] @@ -437,6 +452,7 @@ async def _run(cls): 'ports': [] if is_none(i.spec.ports) else sorted( f'{p.port}/{p.protocol}' for p in i.spec.ports + if p is not None ), } for i in res.items diff --git a/lib/version.py b/lib/version.py index dc0a25b..c7d1c62 100644 --- a/lib/version.py +++ b/lib/version.py @@ -1 +1 @@ -__version__ = '3.1.3' +__version__ = '3.1.4-alpha0'