From: John Mulligan Date: Wed, 7 Jun 2023 13:46:07 +0000 (-0400) Subject: cephadm: add an InitContainer class X-Git-Tag: v19.0.0~711^2~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8391d370cd535a8f3675395115e8275d2f75b9be;p=ceph.git cephadm: add an InitContainer class Add a new InitContainer class that is similar to CephContainer but will not assume certain defaults and is expected to run for a "short" period before exiting. These init containers will be used to preform tasks before a long running container is started. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index ea4c736478a3b..ae1e437559e91 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -4808,6 +4808,64 @@ class CephContainer(BasicContainer): return out +class InitContainer(BasicContainer): + @classmethod + def from_primary_and_opts( + cls, + ctx: CephadmContext, + primary: 'CephContainer', + opts: Dict[str, Any], + data_dir: str = '', + ) -> 'InitContainer': + if not opts: + raise Error('no init container values provided') + # volume mounts are specified relative to a dir in custom container + # if we are going to inherit the dirs from the primary then we + # just copy it. If not, we have to convert the relative paths + # into absolute paths. + assert primary.identity + vmounts = opts.get('volume_mounts') + if not vmounts: + vmounts = primary.volume_mounts + else: + data_dir = data_dir or get_data_dir( + primary.identity.fsid, + ctx.data_dir, + primary.identity.daemon_type, + primary.identity.daemon_id, + ) + vmounts = { + os.path.join(data_dir, src): dst + for src, dst in vmounts.items() + } + return cls( + ctx, + identity=primary.identity._replace(subcomponent='init'), + image=opts.get('image', primary.image), + entrypoint=opts.get('entrypoint', primary.entrypoint), + # note: args is not inherited from primary container + args=opts.get('entrypoint_args', []), + volume_mounts=vmounts, + envs=opts.get('envs', primary.envs), + # note: privileged is not inherited from primary container + # we really ought to minimize running stuff as privileged + privileged=opts.get('privileged', False), + init=False, + ptrace=primary.ptrace, + remove=False, + memory_request=primary.memory_request, + memory_limit=primary.memory_limit, + ) + # Things we are currently not handling: + # container_args, bind_mounts, network, ipc + + def run_cmd(self) -> List[str]: + return self.build_run_cmd() + + def rm_cmd(self, storage: bool = False) -> List[str]: + return self.build_rm_cmd(storage=storage) + + ##################################### class MgrListener(Thread):