Merge "Set KOLLA_SERVICE_NAME in Podman containers"

This commit is contained in:
Zuul 2024-09-11 14:40:25 +00:00 committed by Gerrit Code Review
commit d21adedea8
4 changed files with 21 additions and 16 deletions

View File

@ -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}

View File

@ -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()

View File

@ -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:

View File

@ -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.