From 89bcfe09f6575487795df9b15feac24a817517e7 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 23 Jun 2023 14:07:06 -0400 Subject: [PATCH] python-common: add init_containers field to CustomContainerSpec This allows custom containers to run init containers before the primary container starts. Signed-off-by: John Mulligan --- src/python-common/ceph/deployment/service_spec.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/python-common/ceph/deployment/service_spec.py b/src/python-common/ceph/deployment/service_spec.py index a72536ce4fe..4181ee2563e 100644 --- a/src/python-common/ceph/deployment/service_spec.py +++ b/src/python-common/ceph/deployment/service_spec.py @@ -1507,6 +1507,7 @@ class CustomContainerSpec(ServiceSpec): extra_container_args: Optional[GeneralArgList] = None, extra_entrypoint_args: Optional[GeneralArgList] = None, custom_configs: Optional[List[CustomConfig]] = None, + init_containers: Optional[List[Union['InitContainerSpec', Dict[str, Any]]]] = None, ): assert service_type == 'container' assert service_id is not None @@ -1532,6 +1533,11 @@ class CustomContainerSpec(ServiceSpec): self.ports = ports self.dirs = dirs self.files = files + self.init_containers: Optional[List['InitContainerSpec']] = None + if init_containers: + self.init_containers = InitContainerSpec.import_values( + init_containers + ) def config_json(self) -> Dict[str, Any]: """ @@ -1564,6 +1570,15 @@ class CustomContainerSpec(ServiceSpec): '"files" and "custom_configs" are mutually exclusive ' '(and both serve the same purpose)') + # use quotes for OrderedDict, getting this to work across py 3.6, 3.7 + # and 3.7+ is suprisingly difficult + def to_json(self) -> "OrderedDict[str, Any]": + data = super().to_json() + ics = data.get('spec', {}).get('init_containers') + if ics: + data['spec']['init_containers'] = [ic.to_json() for ic in ics] + return data + yaml.add_representer(CustomContainerSpec, ServiceSpec.yaml_representer) -- 2.39.5