Prevent TypeError in get_active_endpoint function
Sometimes "endpoints_dict" var can be evaluated to None resulting in "TypeError: 'NoneType' object is not iterable" error. This patch catches the exception while getting list of endpoints and checks the value of endpoints_dict. Also the amount of active endpoints is being logged for debug purposes. Change-Id: I79f6b0b5ced8129b9a28c120b61e3ee050af4336
This commit is contained in:
committed by
Vasyl Saienko
parent
13a683b9c2
commit
cb3afe6f85
@@ -15,7 +15,7 @@ apiVersion: v1
|
|||||||
appVersion: v10.6.7
|
appVersion: v10.6.7
|
||||||
description: OpenStack-Helm MariaDB
|
description: OpenStack-Helm MariaDB
|
||||||
name: mariadb
|
name: mariadb
|
||||||
version: 0.2.57
|
version: 0.2.58
|
||||||
home: https://mariadb.com/kb/en/
|
home: https://mariadb.com/kb/en/
|
||||||
icon: http://badges.mariadb.org/mariadb-badge-180x60.png
|
icon: http://badges.mariadb.org/mariadb-badge-180x60.png
|
||||||
sources:
|
sources:
|
||||||
|
|||||||
@@ -616,13 +616,17 @@ def get_active_endpoints(endpoints_name=direct_svc_name,
|
|||||||
(default direct_svc_name)
|
(default direct_svc_name)
|
||||||
namespace -- namespace to check for endpoints (default pod_namespace)
|
namespace -- namespace to check for endpoints (default pod_namespace)
|
||||||
"""
|
"""
|
||||||
endpoints = k8s_api_instance.read_namespaced_endpoints(
|
try:
|
||||||
name=endpoints_name, namespace=pod_namespace)
|
endpoints = k8s_api_instance.read_namespaced_endpoints(
|
||||||
|
name=endpoints_name, namespace=pod_namespace)
|
||||||
|
except kubernetes.client.rest.ApiException as error:
|
||||||
|
logger.error("Failed to get mariadb service with error: {0}".format(error))
|
||||||
|
raise error
|
||||||
endpoints_dict = endpoints.to_dict()
|
endpoints_dict = endpoints.to_dict()
|
||||||
addresses_index = [
|
active_endpoints = []
|
||||||
i for i, s in enumerate(endpoints_dict['subsets']) if 'addresses' in s
|
if endpoints_dict['subsets']:
|
||||||
][0]
|
active_endpoints = [s['addresses'] for s in endpoints_dict['subsets'] if 'addresses' in s
|
||||||
active_endpoints = endpoints_dict['subsets'][addresses_index]['addresses']
|
][0]
|
||||||
return active_endpoints
|
return active_endpoints
|
||||||
|
|
||||||
|
|
||||||
@@ -638,8 +642,10 @@ def check_for_active_nodes(endpoints_name=direct_svc_name,
|
|||||||
logger.info("Checking for active nodes")
|
logger.info("Checking for active nodes")
|
||||||
active_endpoints = get_active_endpoints()
|
active_endpoints = get_active_endpoints()
|
||||||
if active_endpoints and len(active_endpoints) >= 1:
|
if active_endpoints and len(active_endpoints) >= 1:
|
||||||
|
logger.info("Amount of active endpoints: {0}".format(len(active_endpoints)))
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
logger.info("Amount of active endpoints: 0")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -73,4 +73,5 @@ mariadb:
|
|||||||
- 0.2.55 Improve python3 compatibility
|
- 0.2.55 Improve python3 compatibility
|
||||||
- 0.2.56 Stop running threads on sigkill
|
- 0.2.56 Stop running threads on sigkill
|
||||||
- 0.2.57 Remove useless retries on conflicts during cm update
|
- 0.2.57 Remove useless retries on conflicts during cm update
|
||||||
|
- 0.2.58 Prevent TypeError in get_active_endpoint function
|
||||||
...
|
...
|
||||||
|
|||||||
Reference in New Issue
Block a user