From: Adam King Date: Thu, 4 Apr 2024 18:11:11 +0000 (-0400) Subject: mgr/cephadm: make client-keyring deploying ceph.conf optional X-Git-Tag: v18.2.5~407^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fbced31401f1cf151cffe428c69459337c9fd5c8;p=ceph.git mgr/cephadm: make client-keyring deploying ceph.conf optional There are cases where users would like to manage their own ceph.conf but still have cephadm deploy the client keyrings, so this is being added to facilitate that. Fixes: https://tracker.ceph.com/issues/65335 Signed-off-by: Adam King (cherry picked from commit 0dab95eb4fffb493edc3e542a6613bdb5332a670) --- diff --git a/src/pybind/mgr/cephadm/inventory.py b/src/pybind/mgr/cephadm/inventory.py index ac1cf17f6c6f..5ecb142cb6a0 100644 --- a/src/pybind/mgr/cephadm/inventory.py +++ b/src/pybind/mgr/cephadm/inventory.py @@ -406,12 +406,14 @@ class ClientKeyringSpec(object): mode: Optional[int] = None, uid: Optional[int] = None, gid: Optional[int] = None, + include_ceph_conf: bool = True, ) -> None: self.entity = entity self.placement = placement self.mode = mode or 0o600 self.uid = uid or 0 self.gid = gid or 0 + self.include_ceph_conf = include_ceph_conf def validate(self) -> None: pass @@ -423,6 +425,7 @@ class ClientKeyringSpec(object): 'mode': self.mode, 'uid': self.uid, 'gid': self.gid, + 'include_ceph_conf': self.include_ceph_conf, } @property diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index a5bf493416a2..d7a52b6dc3f3 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1476,7 +1476,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, output = to_format(self.keys.keys.values(), format, many=True, cls=ClientKeyringSpec) else: table = PrettyTable( - ['ENTITY', 'PLACEMENT', 'MODE', 'OWNER', 'PATH'], + ['ENTITY', 'PLACEMENT', 'MODE', 'OWNER', 'PATH', 'INCLUDE_CEPH_CONF'], border=False) table.align = 'l' table.left_padding_width = 0 @@ -1487,6 +1487,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, utils.file_mode_to_str(ks.mode), f'{ks.uid}:{ks.gid}', ks.path, + ks.include_ceph_conf )) output = table.get_string() return HandleCommandResult(stdout=output) @@ -1498,6 +1499,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, placement: str, owner: Optional[str] = None, mode: Optional[str] = None, + no_ceph_conf: bool = False, ) -> HandleCommandResult: """ Add or update client keyring under cephadm management @@ -1520,7 +1522,14 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, else: imode = 0o600 pspec = PlacementSpec.from_string(placement) - ks = ClientKeyringSpec(entity, pspec, mode=imode, uid=uid, gid=gid) + ks = ClientKeyringSpec( + entity, + pspec, + mode=imode, + uid=uid, + gid=gid, + include_ceph_conf=(not no_ceph_conf) + ) self.keys.update(ks) self._kick_serve_loop() return HandleCommandResult() diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index 245b163b6208..ce5db4990f73 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -1228,8 +1228,9 @@ class CephadmServe: if host not in client_files: client_files[host] = {} ceph_conf = (0o644, 0, 0, bytes(config), str(config_digest)) - client_files[host]['/etc/ceph/ceph.conf'] = ceph_conf - client_files[host][f'{cluster_cfg_dir}/ceph.conf'] = ceph_conf + if ks.include_ceph_conf: + client_files[host]['/etc/ceph/ceph.conf'] = ceph_conf + client_files[host][f'{cluster_cfg_dir}/ceph.conf'] = ceph_conf client_key = (ks.mode, ks.uid, ks.gid, keyring.encode('utf-8'), digest) client_files[host][ks.path] = client_key client_files[host][f'{cluster_cfg_dir}/{os.path.basename(ks.path)}'] = client_key diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 9a9f15401f9a..f59eeb6aaca2 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -2111,6 +2111,21 @@ class TestCephadm(object): CephadmServe(cephadm_module)._write_client_files({}, 'host2') CephadmServe(cephadm_module)._write_client_files({}, 'host3') + @mock.patch('cephadm.CephadmOrchestrator.mon_command') + @mock.patch("cephadm.inventory.HostCache.get_host_client_files") + def test_dont_write_etc_ceph_client_files_when_turned_off(self, _get_client_files, _mon_command, cephadm_module): + cephadm_module.keys.update(ClientKeyringSpec('keyring1', PlacementSpec(label='keyring1'), include_ceph_conf=False)) + cephadm_module.inventory.add_host(HostSpec('host1', '1.2.3.1', labels=['keyring1'])) + cephadm_module.cache.update_host_daemons('host1', {}) + + _mon_command.return_value = (0, 'my-keyring', '') + + client_files = CephadmServe(cephadm_module)._calc_client_files() + + assert 'host1' in client_files + assert '/etc/ceph/ceph.keyring1.keyring' in client_files['host1'] + assert '/etc/ceph/ceph.conf' not in client_files['host1'] + def test_etc_ceph_init(self): with with_cephadm_module({'manage_etc_ceph_ceph_conf': True}) as m: assert m.manage_etc_ceph_ceph_conf is True