From cb6e5b3fb175e59684e97fa6bda53bf67cf4ce9c Mon Sep 17 00:00:00 2001 From: Pierre Besson Date: Thu, 27 Oct 2022 11:40:03 +0200 Subject: [PATCH] fix paraId filter for the collator view fix #19 --- app/lib/kubernetes_client.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/lib/kubernetes_client.py b/app/lib/kubernetes_client.py index 9d32f6d..4379237 100644 --- a/app/lib/kubernetes_client.py +++ b/app/lib/kubernetes_client.py @@ -6,20 +6,25 @@ def list_stateful_sets(): - return kubernetes_client.CustomObjectsApi().list_namespaced_custom_object(group="apps", version="v1", plural="statefulsets", namespace=namespace)['items'] + return kubernetes_client.CustomObjectsApi().list_namespaced_custom_object(group="apps", version="v1", + plural="statefulsets", + namespace=namespace)['items'] def list_validator_stateful_sets(role='authority'): stateful_sets = list_stateful_sets() - validator_stateful_sets = list(filter(lambda sts: sts['spec']['template']['metadata']['labels']['role'] == role, stateful_sets)) + validator_stateful_sets = list( + filter(lambda sts: sts['spec']['template']['metadata']['labels'].get('role') == role, stateful_sets)) return list(map(lambda sts: sts['metadata']['name'], validator_stateful_sets)) def list_parachain_collator_stateful_sets(para_id): stateful_sets = kubernetes_client.CustomObjectsApi().list_namespaced_custom_object(group="apps", version="v1", plural="statefulsets", namespace=namespace) - collator_stateful_sets = list(filter(lambda sts: sts['spec']['template']['metadata']['labels']['role'] == 'collator' and - sts['spec']['template']['metadata']['labels']['paraId'] == para_id, - stateful_sets['items'])) + + collator_stateful_sets = list( + filter(lambda sts: sts['spec']['template']['metadata']['labels'].get('role') == 'collator' and + sts['spec']['template']['metadata']['labels'].get('paraId') == para_id, + stateful_sets['items'])) return list(map(lambda sts: sts['metadata']['name'], collator_stateful_sets))