From e0fbbab3b16888c6b6ae193049b0d36874f9c642 Mon Sep 17 00:00:00 2001 From: Martin Hiner Date: Wed, 4 Sep 2024 17:00:41 +0200 Subject: [PATCH] Set KOLLA_SERVICE_NAME in Podman containers Fixes issue in PodmanWorker where it didn't set KOLLA_SERVICE_NAME environment variable when creating new container. Additionally, two methods were moved from DockerWorker to ContainerWorker as they are applicable to both engines. Closes-Bug: #2078940 Change-Id: I273444fc828678d3c6803bce1bc8db1c5366b9b6 Signed-off-by: Martin Hiner --- ansible/module_utils/kolla_container_worker.py | 11 +++++++++++ ansible/module_utils/kolla_docker_worker.py | 11 ----------- ansible/module_utils/kolla_podman_worker.py | 8 +++----- releasenotes/notes/bug-2078940-45db7a8cc224d586.yaml | 7 +++++++ 4 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 releasenotes/notes/bug-2078940-45db7a8cc224d586.yaml diff --git a/ansible/module_utils/kolla_container_worker.py b/ansible/module_utils/kolla_container_worker.py index 7fdf541758..bc0f3b4715 100644 --- a/ansible/module_utils/kolla_container_worker.py +++ b/ansible/module_utils/kolla_container_worker.py @@ -565,3 +565,14 @@ class ContainerWorker(ABC): @abstractmethod def ensure_image(self): pass + + def _inject_env_var(self, environment_info): + newenv = { + 'KOLLA_SERVICE_NAME': self.params.get('name').replace('_', '-') + } + environment_info.update(newenv) + return environment_info + + def _format_env_vars(self): + env = self._inject_env_var(self.params.get('environment')) + return {k: "" if env[k] is None else env[k] for k in env} diff --git a/ansible/module_utils/kolla_docker_worker.py b/ansible/module_utils/kolla_docker_worker.py index 2daf13eab9..cd8fdbb572 100644 --- a/ansible/module_utils/kolla_docker_worker.py +++ b/ansible/module_utils/kolla_docker_worker.py @@ -310,17 +310,6 @@ class DockerWorker(ContainerWorker): return host_config - def _inject_env_var(self, environment_info): - newenv = { - 'KOLLA_SERVICE_NAME': self.params.get('name').replace('_', '-') - } - environment_info.update(newenv) - return environment_info - - def _format_env_vars(self): - env = self._inject_env_var(self.params.get('environment')) - return {k: "" if env[k] is None else env[k] for k in env} - def build_container_options(self): volumes, binds = self.generate_volumes() diff --git a/ansible/module_utils/kolla_podman_worker.py b/ansible/module_utils/kolla_podman_worker.py index 757f5f461a..f0073cef69 100644 --- a/ansible/module_utils/kolla_podman_worker.py +++ b/ansible/module_utils/kolla_podman_worker.py @@ -94,11 +94,9 @@ class PodmanWorker(ContainerWorker): args['mounts'] = mounts args['volumes'] = filtered_volumes - # in case value is not string it has to be converted - environment = self.params.get('environment') - if environment: - for key, value in environment.items(): - environment[key] = str(value) + env = self._format_env_vars() + args['environment'] = {k: str(v) for k, v in env.items()} + self.params.pop('environment', None) healthcheck = self.params.get('healthcheck') if healthcheck: diff --git a/releasenotes/notes/bug-2078940-45db7a8cc224d586.yaml b/releasenotes/notes/bug-2078940-45db7a8cc224d586.yaml new file mode 100644 index 0000000000..01697145aa --- /dev/null +++ b/releasenotes/notes/bug-2078940-45db7a8cc224d586.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes issue in PodmanWorker where it didn't set KOLLA_SERVICE_NAME + environment variable when creating new container. + Additionally, two methods were moved from DockerWorker + to ContainerWorker as they are applicable to both engines.