Skip to content
Snippets Groups Projects
Commit ae23848c authored by garciadeblas's avatar garciadeblas
Browse files

Improve logs in readiness_loop for each iteration


Change-Id: If1b78eb4619cebf2b85cad6f4fc4b2efde66633c
Signed-off-by: default avatargarciadeblas <gerardo.garciadeblas@telefonica.com>
parent d7d8bdec
No related branches found
No related tags found
No related merge requests found
......@@ -2054,7 +2054,7 @@ class KsuLcm(GitOpsLcm):
for db_cluster in dbcluster_list:
try:
self.logger.info(
f"Checking status of KSU in cluster {db_cluster['name']}."
f"Checking status of KSU {db_ksu['name']} in cluster {db_cluster['name']}."
)
cluster_kubectl = self.cluster_kubectl(db_cluster)
checkings_list = [
......
......@@ -107,7 +107,7 @@ async def readiness_loop(
if deleted:
if generic_object:
self.logger.info(
f"Found {api_plural}. Name: {name}. Namespace: '{namespace}'. API: {api_group}/{api_version}"
f"Iteration {counter}/{max_iterations}: Found {api_plural}. Name: {name}. Namespace: '{namespace}'. API: {api_group}/{api_version}"
)
else:
self.logger.info(
......@@ -118,29 +118,41 @@ async def readiness_loop(
if not condition:
return True, "Nothing to check"
if generic_object:
# If there is object, conditions must be checked
# self.logger.debug(f"{yaml.safe_dump(generic_object)}")
conditions = generic_object.get("status", {}).get("conditions", [])
self.logger.info(f"{item} status conditions: {conditions}")
else:
self.logger.info(
f"Could not find {api_plural}. Name: {name}. Namespace: '{namespace}'. API: {api_group}/{api_version}"
f"Iteration {counter}/{max_iterations}. Object found: {item} status conditions: {conditions}"
)
conditions = []
jsonpath_expr = parse(condition["jsonpath_filter"])
match = jsonpath_expr.find(generic_object)
if match:
value = match[0].value
condition_function = condition.get("function", lambda x, y: x == y)
if condition_function(condition["value"], value):
jsonpath_expr = parse(condition["jsonpath_filter"])
match = jsonpath_expr.find(generic_object)
if match:
value = match[0].value
condition_function = condition.get(
"function", lambda x, y: x == y
)
if condition_function(condition["value"], value):
self.logger.info(
f"{item} {name} met the condition {condition} with {value} in {counter} iterations (aprox {counter*retry_time} seconds)"
)
return True, "COMPLETED"
else:
self.logger.info(
f"Iteration {counter}/{max_iterations}: {item} {name} did not meet the condition {condition} with value {value}"
)
else:
self.logger.info(
f"{item} {name} met the condition {condition} in {counter} iterations (aprox {counter*retry_time} seconds)"
f"Iteration {counter}/{max_iterations}. No match for filter {condition.get('jsonpath_filter', '-')} in {item} {name}"
)
return True, "COMPLETED"
else:
self.logger.info(
f"Iteration {counter}/{max_iterations}: Could not find {api_plural}. Name: {name}. Namespace: '{namespace}'. API: {api_group}/{api_version}"
)
except Exception as e:
self.logger.error(f"Exception: {e}")
await asyncio.sleep(retry_time)
counter += 1
return (
False,
"{item} {name} was not ready after {max_iterations} iterations (aprox {timeout} seconds)",
f"{item} {name} was not ready after {max_iterations} iterations (aprox {timeout} seconds)",
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment