From 3c875aa98bc2329b3cbca763af17a9a7cbc3921b Mon Sep 17 00:00:00 2001 From: Adam King Date: Mon, 28 Feb 2022 20:23:10 -0500 Subject: [PATCH] mgr/cephadm: block removing last instance of _admin label Fixes: https://tracker.ceph.com/issues/54425 Signed-off-by: Adam King (cherry picked from commit fbe0c3fd23f9005986959bade149093c340f6238) Conflicts: src/pybind/mgr/rook/module.py --- src/pybind/mgr/cephadm/module.py | 14 +++++++++++++- src/pybind/mgr/orchestrator/_interface.py | 2 +- src/pybind/mgr/orchestrator/module.py | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 13b5040ed98bc..a6ad4f84d4170 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1651,7 +1651,19 @@ Then run the following: return 'Added label %s to host %s' % (label, host) @handle_orch_error - def remove_host_label(self, host: str, label: str) -> str: + def remove_host_label(self, host: str, label: str, force: bool = False) -> str: + # if we remove the _admin label from the only host that has it we could end up + # removing the only instance of the config and keyring and cause issues + if not force and label == '_admin': + p = PlacementSpec(label='_admin') + admin_hosts = p.filter_matching_hostspecs(self.inventory.all_specs()) + if len(admin_hosts) == 1 and admin_hosts[0] == host: + raise OrchestratorValidationError(f"Host {host} is the last host with the '_admin'" + " label.\nRemoving the _admin label from this host could cause the removal" + " of the last cluster config/keyring managed by cephadm.\n" + "It is recommended to add the _admin label to another host" + " before completing this operation.\nIf you're certain this is" + " what you want rerun this command with --force.") self.inventory.rm_label(host, label) self.log.info('Removed label %s to host %s' % (label, host)) self._kick_serve_loop() diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index a1b1893db0cdf..69c04acd83d41 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -392,7 +392,7 @@ class Orchestrator(object): """ raise NotImplementedError() - def remove_host_label(self, host: str, label: str) -> OrchResult[str]: + def remove_host_label(self, host: str, label: str, force: bool = False) -> OrchResult[str]: """ Remove a host label """ diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index 10381db9c14a7..340710eb8cc58 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -418,9 +418,9 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, return HandleCommandResult(stdout=completion.result_str()) @_cli_write_command('orch host label rm') - def _host_label_rm(self, hostname: str, label: str) -> HandleCommandResult: + def _host_label_rm(self, hostname: str, label: str, force: bool = False) -> HandleCommandResult: """Remove a host label""" - completion = self.remove_host_label(hostname, label) + completion = self.remove_host_label(hostname, label, force) raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) -- 2.39.5