Skip to content

Commit b348e15

Browse files
authored
Prevent validation error if observability configmap not set (#36)
* Prevent validation error if observability configmap not set
1 parent ac34a7d commit b348e15

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/suite_starter/suite_starter.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ def _get_current_context(self):
109109
env = ",".join(f"{k}={v}" for k, v in carrier.items())
110110
return env
111111

112+
@classmethod
113+
def remove_empty_configmaps(cls, data):
114+
"""Iterate the ESR configuration dict recursively and remove empty configmaps."""
115+
element_to_remove = {"configMapRef": {"name": "None"}}
116+
if isinstance(data, dict):
117+
for key, value in list(data.items()):
118+
if value == element_to_remove:
119+
del data[key]
120+
else:
121+
cls.remove_empty_configmaps(value)
122+
elif isinstance(data, list):
123+
while element_to_remove in data:
124+
data.remove(element_to_remove)
125+
for item in data:
126+
cls.remove_empty_configmaps(item)
127+
112128
def suite_runner_callback(self, event, _):
113129
"""Start a suite runner on a TERCC event.
114130
@@ -144,6 +160,9 @@ def suite_runner_callback(self, event, _):
144160
body = job.load_yaml(
145161
self.suite_runner_template.format(**data, **self.etos.config.get("configuration"))
146162
)
163+
# Handle cases when some configmaps aren't set (e. g. etos_observability_configmap):
164+
self.remove_empty_configmaps(body)
165+
147166
LOGGER.info("Starting new executor: %r", job_name)
148167
job.create_job(body)
149168
LOGGER.info("ESR successfully launched.")

0 commit comments

Comments
 (0)