From c0524e31c2b46f4d24aaa45192ac5b5bd03a36de Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sun, 8 Mar 2020 21:17:47 -0500 Subject: [PATCH] mgr/cephadm: apply: fill in default placement if none is provided Most stateless daemons get 2x (so there is a standby). Monitoring items get just 1x. By default we do 5 monitors, which will gracefully degrade to one per host if the cluster has <5 hosts. Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 18 +++++++++++++++++- src/pybind/mgr/orchestrator/_interface.py | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 945f0c3a6668..3ccf8b70c218 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2359,7 +2359,23 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): return self._add_daemon('mgr', spec, self._create_mgr) def _apply(self, spec): - self.log.info('Saving service %s spec' % spec.service_name()) + if spec.placement.is_empty(): + # fill in default placement + defaults = { + 'mon': orchestrator.PlacementSpec(count=5), + 'mgr': orchestrator.PlacementSpec(count=2), + 'mds': orchestrator.PlacementSpec(count=2), + 'rgw': orchestrator.PlacementSpec(count=2), + 'rbd-mirror': orchestrator.PlacementSpec(count=2), + 'grafana': orchestrator.PlacementSpec(count=1), + 'alertmanager': orchestrator.PlacementSpec(count=1), + 'prometheus': orchestrator.PlacementSpec(count=1), + 'node-exporter': orchestrator.PlacementSpec(all_hosts=True), + 'crash': orchestrator.PlacementSpec(all_hosts=True), + } + spec.placement = defaults[spec.service_type] + self.log.info('Saving service %s spec with placement %s' % ( + spec.service_name(), spec.placement.pretty_str())) self.spec_store.save(spec) self._kick_serve_loop() return trivial_result("Scheduled %s update..." % spec.service_type) diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 3f0e5dab5792..af380d98e5b7 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -1267,6 +1267,12 @@ class PlacementSpec(object): self.count = count # type: Optional[int] self.all_hosts = all_hosts # type: bool + def is_empty(self): + return not self.all_hosts and \ + self.label is None and \ + not self.hosts and \ + self.count is None + def set_hosts(self, hosts): # To backpopulate the .hosts attribute when using labels or count # in the orchestrator backend. -- 2.47.3