]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add function to write init container commands
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 14 Jun 2023 16:02:00 +0000 (12:02 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 9 Aug 2023 17:48:07 +0000 (13:48 -0400)
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 <jmulligan@redhat.com>
src/cephadm/cephadm.py

index ae1e437559e911b526495cca5e6ed60832043752..441fe4866a1d502e1c242d68fdd668aad10b545a 100755 (executable)
@@ -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