From: John Mulligan Date: Wed, 14 Jun 2023 16:02:00 +0000 (-0400) Subject: cephadm: add function to write init container commands X-Git-Tag: v19.0.0~711^2~15 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0a1310e29b5259134fff13cc9b651ba8101276e5;p=ceph-ci.git cephadm: add function to write init container commands Add functions that write commands to clean up and execute init containers. These init containers will be executed before the main container as part of unit.run files (for now). Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index ae1e437559e..441fe4866a1 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -3819,6 +3819,42 @@ def _write_container_cmd_to_bash( _bash_cmd(file_obj, container.run_cmd(), background=bool(background)) +def _write_init_container_cmds( + ctx: CephadmContext, + file_obj: IO[str], + index: int, + init_container: 'InitContainer', +) -> None: + file_obj.write(f'# init container {index}: {init_container.cname}\n') + _bash_cmd(file_obj, init_container.run_cmd()) + _write_init_container_cmds_clean(ctx, file_obj, init_container, comment='') + + +def _write_init_container_cmds_clean( + ctx: CephadmContext, + file_obj: IO[str], + init_container: 'InitContainer', + comment: str = 'init container cleanup', +) -> None: + if comment: + assert '\n' not in comment + file_obj.write(f'# {comment}\n') + _bash_cmd( + file_obj, + init_container.rm_cmd(), + check=False, + stderr=False, + ) + # Sometimes, `podman rm` doesn't find the container. Then you'll have to add `--storage` + if isinstance(ctx.container_engine, Podman): + _bash_cmd( + file_obj, + init_container.rm_cmd(storage=True), + check=False, + stderr=False, + ) + + def clean_cgroup(ctx: CephadmContext, fsid: str, unit_name: str) -> None: # systemd may fail to cleanup cgroups from previous stopped unit, which will cause next "systemctl start" to fail. # see https://tracker.ceph.com/issues/50998