diff options
author | John Mulligan <jmulligan@redhat.com> | 2023-09-23 21:28:25 +0200 |
---|---|---|
committer | John Mulligan <jmulligan@redhat.com> | 2023-10-04 21:17:57 +0200 |
commit | be3e552717881fc6e70cc4bdf4302719d1565c9e (patch) | |
tree | e6de0e3d61e68c0392a21c3c81360e14b282cc4a | |
parent | cephadm: convert NFSGanesha to a ContainerDaemonForm (diff) | |
download | ceph-be3e552717881fc6e70cc4bdf4302719d1565c9e.tar.xz ceph-be3e552717881fc6e70cc4bdf4302719d1565c9e.zip |
cephadm: convert CustomContainer to a ContainerDaemonForm
Signed-off-by: John Mulligan <jmulligan@redhat.com>
-rwxr-xr-x | src/cephadm/cephadm.py | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 43d3d453d8f..97419dded0b 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -1396,7 +1396,7 @@ class Tracing(DaemonForm): @register_daemon_form -class CustomContainer(DaemonForm): +class CustomContainer(ContainerDaemonForm): """Defines a custom container""" daemon_type = 'container' @@ -1519,6 +1519,39 @@ class CustomContainer(DaemonForm): data_dir, match.group(1))) return binds + # Cache the container so we don't need to rebuild it again when calling + # into init_containers + _container: Optional[CephContainer] = None + + def container(self, ctx: CephadmContext) -> CephContainer: + if self._container is None: + self._container = get_deployment_container( + ctx, + self.identity, + privileged=self.privileged, + ptrace=ctx.allow_ptrace, + ) + return self._container + + def init_containers(self, ctx: CephadmContext) -> List[InitContainer]: + primary = self.container(ctx) + init_containers: List[Dict[str, Any]] = getattr( + ctx, 'init_containers', [] + ) + return [ + InitContainer.from_primary_and_opts(ctx, primary, ic_opts) + for ic_opts in init_containers + ] + + def customize_container_endpoints( + self, endpoints: List[EndPoint], deployment_type: DeploymentType + ) -> None: + if deployment_type == DeploymentType.DEFAULT: + endpoints.extend([EndPoint('0.0.0.0', p) for p in self.ports]) + + def uid_gid(self, ctx: CephadmContext) -> Tuple[int, int]: + return self.uid, self.gid + ################################## @@ -4972,17 +5005,6 @@ def get_deployment_container( return c -def get_deployment_init_containers( - ctx: CephadmContext, - primary_container: 'CephContainer', -) -> List['InitContainer']: - init_containers: List[Dict[str, Any]] = getattr(ctx, 'init_containers', []) - return [ - InitContainer.from_primary_and_opts(ctx, primary_container, ic_opts) - for ic_opts in init_containers - ] - - def get_deployment_type( ctx: CephadmContext, ident: 'DaemonIdentity', ) -> DeploymentType: @@ -5205,31 +5227,6 @@ def _dispatch_deploy( endpoints=daemon_endpoints, ) - elif daemon_type == CustomContainer.daemon_type: - cc = CustomContainer.init(ctx, ident.fsid, ident.daemon_id) - # only check ports if this is a fresh deployment - if deployment_type == DeploymentType.DEFAULT: - daemon_endpoints.extend([EndPoint('0.0.0.0', p) for p in cc.ports]) - c = get_deployment_container( - ctx, ident, privileged=cc.privileged, ptrace=ctx.allow_ptrace - ) - ics = get_deployment_init_containers( - ctx, - c, - ) - deploy_daemon( - ctx, - ident, - c, - uid=cc.uid, - gid=cc.gid, - config=None, - keyring=None, - deployment_type=deployment_type, - endpoints=daemon_endpoints, - init_containers=ics, - ) - elif daemon_type == CephadmAgent.daemon_type: # get current user gid and uid uid = os.getuid() |