From 5b8c155a33283aaa5854911572b20923fa563390 Mon Sep 17 00:00:00 2001 From: Kushal Deb Date: Wed, 15 Jan 2025 10:43:44 +0530 Subject: [PATCH] cephadm: link new OSDs to existing managed services Added logic for new OSDs to link to existing managed services. The create_osds function now dynamically assigns service_id based on matching entries in the spec_store. If no service name is provided, it creates the OSDs with 'osd.default' service name and they remain unmanaged. Signed-off-by: Kushal Deb --- doc/cephadm/services/osd.rst | 12 ++++--- qa/suites/orch/cephadm/smoke-small/start.yaml | 2 +- qa/suites/orch/cephadm/smoke/start.yaml | 2 +- qa/suites/orch/cephadm/upgrade/4-wait.yaml | 2 +- src/pybind/mgr/cephadm/module.py | 33 +++++++++++++++++++ 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/doc/cephadm/services/osd.rst b/doc/cephadm/services/osd.rst index bb461478e56f..97d0b1449033 100644 --- a/doc/cephadm/services/osd.rst +++ b/doc/cephadm/services/osd.rst @@ -199,17 +199,19 @@ There are multiple ways to create new OSDs: .. warning:: When deploying new OSDs with ``cephadm``, ensure that the ``ceph-osd`` package is not installed on the target host. If it is installed, conflicts may arise in the management and control of the OSD that may lead to errors or unexpected behavior. -* OSDs created via ``ceph orch daemon add`` are by default not added to the orchestrator's OSD service. To attach an OSD to a different, existing OSD service, issue a command of the following form: +* New OSDs created using ``ceph orch daemon add osd`` are added under ``osd.default`` as managed OSDs with a valid spec. - .. prompt:: bash * + To attach an existing OSD to a different managed service, ``ceph orch osd set-spec-affinity`` command can be used: - ceph orch osd set-spec-affinity + .. prompt:: bash # + + ceph orch osd set-spec-affinity For example: .. prompt:: bash # - - ceph orch osd set-spec-affinity osd.default_drive_group 0 1 + + ceph orch osd set-spec-affinity osd.default_drive_group 0 1 Dry Run ------- diff --git a/qa/suites/orch/cephadm/smoke-small/start.yaml b/qa/suites/orch/cephadm/smoke-small/start.yaml index 7d89f23d3f85..ced1a553ec88 100644 --- a/qa/suites/orch/cephadm/smoke-small/start.yaml +++ b/qa/suites/orch/cephadm/smoke-small/start.yaml @@ -20,4 +20,4 @@ tasks: - ceph orch host ls - ceph orch device ls - ceph orch ls --format yaml - - ceph orch ls | grep '^osd ' + - ceph orch ls | grep 'osd' diff --git a/qa/suites/orch/cephadm/smoke/start.yaml b/qa/suites/orch/cephadm/smoke/start.yaml index 9c413a61d40a..396e29ed98cb 100644 --- a/qa/suites/orch/cephadm/smoke/start.yaml +++ b/qa/suites/orch/cephadm/smoke/start.yaml @@ -25,4 +25,4 @@ tasks: - ceph orch host ls - ceph orch device ls - ceph orch ls --format yaml - - ceph orch ls | grep '^osd ' + - ceph orch ls | grep 'osd' diff --git a/qa/suites/orch/cephadm/upgrade/4-wait.yaml b/qa/suites/orch/cephadm/upgrade/4-wait.yaml index 4010c58ed779..16dded25856c 100644 --- a/qa/suites/orch/cephadm/upgrade/4-wait.yaml +++ b/qa/suites/orch/cephadm/upgrade/4-wait.yaml @@ -13,4 +13,4 @@ tasks: - ceph health detail - ceph versions | jq -e '.overall | length == 1' - ceph versions | jq -e '.overall | keys' | grep $sha1 - - ceph orch ls | grep '^osd ' + - ceph orch ls | grep 'osd' diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index f1775da3c210..0adf88bdb0b9 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -42,6 +42,7 @@ from ceph.deployment.service_spec import ( MgmtGatewaySpec, NvmeofServiceSpec, ) +from ceph.deployment.drive_group import DeviceSelection from ceph.utils import str_to_datetime, datetime_to_str, datetime_now from cephadm.serve import CephadmServe from cephadm.services.cephadmservice import CephadmDaemonDeploySpec @@ -2867,12 +2868,44 @@ Then run the following: """ return [self._apply(spec) for spec in specs] + def create_osd_default_spec(self, drive_group: DriveGroupSpec) -> None: + # Create the default osd and attach a valid spec to it. + + drive_group.unmanaged = False + + host_pattern_obj = drive_group.placement.host_pattern + host = str(host_pattern_obj.pattern) + device_list = [d.path for d in drive_group.data_devices.paths] if drive_group.data_devices else [] + devices = [{"path": d} for d in device_list] + + osd_default_spec = DriveGroupSpec( + service_id="default", + placement=PlacementSpec(host_pattern=host), + data_devices=DeviceSelection(paths=devices), + unmanaged=False, + objectstore="bluestore" + ) + + self.log.info(f"Creating OSDs with service ID: {drive_group.service_id} on {host}:{device_list}") + self.spec_store.save(osd_default_spec) + self.apply([osd_default_spec]) + @handle_orch_error def create_osds(self, drive_group: DriveGroupSpec) -> str: hosts: List[HostSpec] = self.inventory.all_specs() filtered_hosts: List[str] = drive_group.placement.filter_matching_hostspecs(hosts) if not filtered_hosts: return "Invalid 'host:device' spec: host not found in cluster. Please check 'ceph orch host ls' for available hosts" + + if not drive_group.service_id: + drive_group.service_id = "default" + + if drive_group.service_id not in self.spec_store.all_specs: + self.log.info("osd.default does not exist. Creating it now.") + self.create_osd_default_spec(drive_group) + else: + self.log.info("osd.default already exists.") + return self.osd_service.create_from_spec(drive_group) def _preview_osdspecs(self, -- 2.47.3