]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add an InitContainer class
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 7 Jun 2023 13:46:07 +0000 (09:46 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 9 Aug 2023 17:48:07 +0000 (13:48 -0400)
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 <jmulligan@redhat.com>
src/cephadm/cephadm.py

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