From: John Mulligan Date: Sat, 21 Oct 2023 15:41:15 +0000 (-0400) Subject: cephadm: move option for setting unlimited pids into engine classes X-Git-Tag: v19.0.0~145^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=69c7670b6c6c7f0df386b48ce30b2f25c705d8b5;p=ceph.git cephadm: move option for setting unlimited pids into engine classes Move the option for setting unlimited pids for the container engine into the container engine classes. This continues the attempts to improve the locality of items specific to certain classes to be by making them part of the classes. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 641b269c132..650e080843e 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -70,7 +70,6 @@ from cephadmlib.constants import ( LOGROTATE_DIR, LOG_DIR, LOG_DIR_MODE, - PIDS_LIMIT_UNLIMITED_PODMAN_VERSION, SYSCTL_DIR, UNIT_DIR, ) @@ -2692,13 +2691,7 @@ def _update_pids_limit(ctx: CephadmContext, daemon_type: str, container_args: Li unlimited_daemons.add(NFSGanesha.daemon_type) if daemon_type not in unlimited_daemons: return - if ( - isinstance(ctx.container_engine, Podman) - and ctx.container_engine.version >= PIDS_LIMIT_UNLIMITED_PODMAN_VERSION - ): - container_args.append('--pids-limit=-1') - else: - container_args.append('--pids-limit=0') + container_args.append(ctx.container_engine.unlimited_pids_option) def get_container( diff --git a/src/cephadm/cephadmlib/container_engine_base.py b/src/cephadm/cephadmlib/container_engine_base.py index 135b2f4f321..c8d4bfbcf29 100644 --- a/src/cephadm/cephadmlib/container_engine_base.py +++ b/src/cephadm/cephadmlib/container_engine_base.py @@ -11,5 +11,12 @@ class ContainerEngine: def EXE(self) -> str: raise NotImplementedError() + @property + def unlimited_pids_option(self) -> str: + """The option to pass to the container engine for allowing unlimited + pids (processes). + """ + return '--pids-limit=0' + def __str__(self) -> str: return f'{self.EXE} ({self.path})' diff --git a/src/cephadm/cephadmlib/container_engines.py b/src/cephadm/cephadmlib/container_engines.py index 8ced8ab3ff4..98019fa820b 100644 --- a/src/cephadm/cephadmlib/container_engines.py +++ b/src/cephadm/cephadmlib/container_engines.py @@ -11,6 +11,7 @@ from .constants import ( CGROUPS_SPLIT_PODMAN_VERSION, DEFAULT_MODE, MIN_PODMAN_VERSION, + PIDS_LIMIT_UNLIMITED_PODMAN_VERSION, ) from .exceptions import Error @@ -45,6 +46,15 @@ class Podman(ContainerEngine): """Return true if this version of podman supports split cgroups.""" return self.version >= CGROUPS_SPLIT_PODMAN_VERSION + @property + def unlimited_pids_option(self) -> str: + """The option to pass to the container engine for allowing unlimited + pids (processes). + """ + if self.version >= PIDS_LIMIT_UNLIMITED_PODMAN_VERSION: + return '--pids-limit=-1' + return '--pids-limit=0' + def service_args( self, ctx: CephadmContext, service_name: str ) -> List[str]: diff --git a/src/cephadm/tests/fixtures.py b/src/cephadm/tests/fixtures.py index 86a8c6119ea..d25dffa9e3b 100644 --- a/src/cephadm/tests/fixtures.py +++ b/src/cephadm/tests/fixtures.py @@ -21,6 +21,7 @@ def mock_docker(): docker = mock.Mock(Docker) docker.path = '/usr/bin/docker' + type(docker).unlimited_pids_option = Docker.unlimited_pids_option return docker @@ -37,6 +38,7 @@ def mock_podman(): # https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock type(podman).supports_split_cgroups = Podman.supports_split_cgroups type(podman).service_args = Podman.service_args + type(podman).unlimited_pids_option = Podman.unlimited_pids_option return podman