Skip to content

Commit

Permalink
Prevent validation error if observability configmap not set (#36)
Browse files Browse the repository at this point in the history
* Prevent validation error if observability configmap not set
  • Loading branch information
andmat900 authored May 8, 2024
1 parent ac34a7d commit b348e15
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/suite_starter/suite_starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ def _get_current_context(self):
env = ",".join(f"{k}={v}" for k, v in carrier.items())
return env

@classmethod
def remove_empty_configmaps(cls, data):
"""Iterate the ESR configuration dict recursively and remove empty configmaps."""
element_to_remove = {"configMapRef": {"name": "None"}}
if isinstance(data, dict):
for key, value in list(data.items()):
if value == element_to_remove:
del data[key]
else:
cls.remove_empty_configmaps(value)
elif isinstance(data, list):
while element_to_remove in data:
data.remove(element_to_remove)
for item in data:
cls.remove_empty_configmaps(item)

def suite_runner_callback(self, event, _):
"""Start a suite runner on a TERCC event.
Expand Down Expand Up @@ -144,6 +160,9 @@ def suite_runner_callback(self, event, _):
body = job.load_yaml(
self.suite_runner_template.format(**data, **self.etos.config.get("configuration"))
)
# Handle cases when some configmaps aren't set (e. g. etos_observability_configmap):
self.remove_empty_configmaps(body)

LOGGER.info("Starting new executor: %r", job_name)
job.create_job(body)
LOGGER.info("ESR successfully launched.")
Expand Down

0 comments on commit b348e15

Please sign in to comment.