Skip to content

Commit 0dab95e

Browse files
committed
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 <[email protected]>
1 parent 9e2327f commit 0dab95e

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/pybind/mgr/cephadm/inventory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,14 @@ def __init__(
406406
mode: Optional[int] = None,
407407
uid: Optional[int] = None,
408408
gid: Optional[int] = None,
409+
include_ceph_conf: bool = True,
409410
) -> None:
410411
self.entity = entity
411412
self.placement = placement
412413
self.mode = mode or 0o600
413414
self.uid = uid or 0
414415
self.gid = gid or 0
416+
self.include_ceph_conf = include_ceph_conf
415417

416418
def validate(self) -> None:
417419
pass
@@ -423,6 +425,7 @@ def to_json(self) -> Dict[str, Any]:
423425
'mode': self.mode,
424426
'uid': self.uid,
425427
'gid': self.gid,
428+
'include_ceph_conf': self.include_ceph_conf,
426429
}
427430

428431
@property

src/pybind/mgr/cephadm/module.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ def _client_keyring_ls(self, format: Format = Format.plain) -> HandleCommandResu
15211521
output = to_format(self.keys.keys.values(), format, many=True, cls=ClientKeyringSpec)
15221522
else:
15231523
table = PrettyTable(
1524-
['ENTITY', 'PLACEMENT', 'MODE', 'OWNER', 'PATH'],
1524+
['ENTITY', 'PLACEMENT', 'MODE', 'OWNER', 'PATH', 'INCLUDE_CEPH_CONF'],
15251525
border=False)
15261526
table.align = 'l'
15271527
table.left_padding_width = 0
@@ -1532,6 +1532,7 @@ def _client_keyring_ls(self, format: Format = Format.plain) -> HandleCommandResu
15321532
utils.file_mode_to_str(ks.mode),
15331533
f'{ks.uid}:{ks.gid}',
15341534
ks.path,
1535+
ks.include_ceph_conf
15351536
))
15361537
output = table.get_string()
15371538
return HandleCommandResult(stdout=output)
@@ -1543,6 +1544,7 @@ def _client_keyring_set(
15431544
placement: str,
15441545
owner: Optional[str] = None,
15451546
mode: Optional[str] = None,
1547+
no_ceph_conf: bool = False,
15461548
) -> HandleCommandResult:
15471549
"""
15481550
Add or update client keyring under cephadm management
@@ -1565,7 +1567,14 @@ def _client_keyring_set(
15651567
else:
15661568
imode = 0o600
15671569
pspec = PlacementSpec.from_string(placement)
1568-
ks = ClientKeyringSpec(entity, pspec, mode=imode, uid=uid, gid=gid)
1570+
ks = ClientKeyringSpec(
1571+
entity,
1572+
pspec,
1573+
mode=imode,
1574+
uid=uid,
1575+
gid=gid,
1576+
include_ceph_conf=(not no_ceph_conf)
1577+
)
15691578
self.keys.update(ks)
15701579
self._kick_serve_loop()
15711580
return HandleCommandResult()

src/pybind/mgr/cephadm/serve.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,8 +1232,9 @@ def _calc_client_files(self) -> Dict[str, Dict[str, Tuple[int, int, int, bytes,
12321232
if host not in client_files:
12331233
client_files[host] = {}
12341234
ceph_conf = (0o644, 0, 0, bytes(config), str(config_digest))
1235-
client_files[host]['/etc/ceph/ceph.conf'] = ceph_conf
1236-
client_files[host][f'{cluster_cfg_dir}/ceph.conf'] = ceph_conf
1235+
if ks.include_ceph_conf:
1236+
client_files[host]['/etc/ceph/ceph.conf'] = ceph_conf
1237+
client_files[host][f'{cluster_cfg_dir}/ceph.conf'] = ceph_conf
12371238
client_key = (ks.mode, ks.uid, ks.gid, keyring.encode('utf-8'), digest)
12381239
client_files[host][ks.path] = client_key
12391240
client_files[host][f'{cluster_cfg_dir}/{os.path.basename(ks.path)}'] = client_key

src/pybind/mgr/cephadm/tests/test_cephadm.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,21 @@ def test_dont_write_client_files_to_unreachable_hosts(self, _get_client_files, c
21112111
CephadmServe(cephadm_module)._write_client_files({}, 'host2')
21122112
CephadmServe(cephadm_module)._write_client_files({}, 'host3')
21132113

2114+
@mock.patch('cephadm.CephadmOrchestrator.mon_command')
2115+
@mock.patch("cephadm.inventory.HostCache.get_host_client_files")
2116+
def test_dont_write_etc_ceph_client_files_when_turned_off(self, _get_client_files, _mon_command, cephadm_module):
2117+
cephadm_module.keys.update(ClientKeyringSpec('keyring1', PlacementSpec(label='keyring1'), include_ceph_conf=False))
2118+
cephadm_module.inventory.add_host(HostSpec('host1', '1.2.3.1', labels=['keyring1']))
2119+
cephadm_module.cache.update_host_daemons('host1', {})
2120+
2121+
_mon_command.return_value = (0, 'my-keyring', '')
2122+
2123+
client_files = CephadmServe(cephadm_module)._calc_client_files()
2124+
2125+
assert 'host1' in client_files
2126+
assert '/etc/ceph/ceph.keyring1.keyring' in client_files['host1']
2127+
assert '/etc/ceph/ceph.conf' not in client_files['host1']
2128+
21142129
def test_etc_ceph_init(self):
21152130
with with_cephadm_module({'manage_etc_ceph_ceph_conf': True}) as m:
21162131
assert m.manage_etc_ceph_ceph_conf is True

0 commit comments

Comments
 (0)