Merge pull request #39323 from sebastian-philipp/cephadm-simplify-cephadmservice-config

mgr/cephadm: Add config() to CephadmService

Reviewed-by: Juan Miguel Olmo Martínez <jolmomar@redhat.com>
This commit is contained in:
Sebastian Wagner 2021-02-16 18:00:40 +01:00 committed by GitHub
commit 6871b0da8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 38 deletions

View File

@ -1895,8 +1895,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
def _add_daemon(self,
daemon_type: str,
spec: ServiceSpec,
create_func: Callable[..., CephadmDaemonSpec],
config_func: Optional[Callable] = None) -> List[str]:
create_func: Callable[..., CephadmDaemonSpec]) -> List[str]:
"""
Add (and place) a daemon. Require explicit host placement. Do not
schedule, and do not apply the related scheduling limitations.
@ -1913,7 +1912,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
daemons = self.cache.get_daemons_by_service(spec.service_name())
return self._create_daemons(daemon_type, spec, daemons,
spec.placement.hosts, count,
create_func, config_func)
create_func)
def _create_daemons(self,
daemon_type: str,
@ -1921,13 +1920,13 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
daemons: List[DaemonDescription],
hosts: List[HostPlacementSpec],
count: int,
create_func: Callable[..., CephadmDaemonSpec],
config_func: Optional[Callable] = None) -> List[str]:
create_func: Callable[..., CephadmDaemonSpec]) -> List[str]:
if count > len(hosts):
raise OrchestratorError('too few hosts: want %d, have %s' % (
count, hosts))
did_config = False
service_type = daemon_type_to_service(daemon_type)
args = [] # type: List[CephadmDaemonSpec]
for host, network, name in hosts:
@ -1935,14 +1934,11 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
prefix=spec.service_id,
forcename=name)
if not did_config and config_func:
if daemon_type == 'rgw':
config_func(spec, daemon_id)
else:
config_func(spec)
if not did_config:
self.cephadm_services[service_type].config(spec, daemon_id)
did_config = True
daemon_spec = self.cephadm_services[daemon_type_to_service(daemon_type)].make_daemon_spec(
daemon_spec = self.cephadm_services[service_type].make_daemon_spec(
host, daemon_id, network, spec)
self.log.debug('Placing %s.%s on host %s' % (
daemon_type, daemon_id, host))
@ -2076,7 +2072,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
@trivial_completion
def add_mds(self, spec: ServiceSpec) -> List[str]:
return self._add_daemon('mds', spec, self.mds_service.prepare_create, self.mds_service.config)
return self._add_daemon('mds', spec, self.mds_service.prepare_create)
@trivial_completion
def apply_mds(self, spec: ServiceSpec) -> str:
@ -2084,7 +2080,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
@trivial_completion
def add_rgw(self, spec: ServiceSpec) -> List[str]:
return self._add_daemon('rgw', spec, self.rgw_service.prepare_create, self.rgw_service.config)
return self._add_daemon('rgw', spec, self.rgw_service.prepare_create)
@trivial_completion
def apply_rgw(self, spec: ServiceSpec) -> str:
@ -2097,7 +2093,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
@trivial_completion
def add_iscsi(self, spec):
# type: (ServiceSpec) -> List[str]
return self._add_daemon('iscsi', spec, self.iscsi_service.prepare_create, self.iscsi_service.config)
return self._add_daemon('iscsi', spec, self.iscsi_service.prepare_create)
@trivial_completion
def apply_iscsi(self, spec: ServiceSpec) -> str:
@ -2113,7 +2109,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
@trivial_completion
def add_nfs(self, spec: ServiceSpec) -> List[str]:
return self._add_daemon('nfs', spec, self.nfs_service.prepare_create, self.nfs_service.config)
return self._add_daemon('nfs', spec, self.nfs_service.prepare_create)
@trivial_completion
def apply_nfs(self, spec: ServiceSpec) -> str:

View File

@ -2,7 +2,7 @@ import json
import logging
from collections import defaultdict
from contextlib import contextmanager
from typing import TYPE_CHECKING, Optional, List, Callable, cast, Set, Dict, Any, Union, Tuple, Iterator
from typing import TYPE_CHECKING, Optional, List, cast, Set, Dict, Any, Union, Tuple, Iterator
from cephadm import remotes
@ -14,7 +14,7 @@ except ImportError:
from ceph.deployment import inventory
from ceph.deployment.drive_group import DriveGroupSpec
from ceph.deployment.service_spec import ServiceSpec, HostPlacementSpec, RGWSpec, \
from ceph.deployment.service_spec import ServiceSpec, HostPlacementSpec, \
HA_RGWSpec, CustomContainerSpec
from ceph.utils import str_to_datetime, datetime_now
@ -443,15 +443,6 @@ class CephadmServe:
return r
def _config_fn(self, service_type: str) -> Optional[Callable[[ServiceSpec], None]]:
fn = {
'mds': self.mgr.mds_service.config,
'rgw': self.mgr.rgw_service.config,
'nfs': self.mgr.nfs_service.config,
'iscsi': self.mgr.iscsi_service.config,
}.get(service_type)
return cast(Callable[[ServiceSpec], None], fn)
def _apply_service(self, spec: ServiceSpec) -> bool:
"""
Schedule a service. Deploy new daemons or remove old ones, depending
@ -469,8 +460,6 @@ class CephadmServe:
return False
self.log.debug('Applying service %s spec' % service_name)
config_func = self._config_fn(service_type)
if service_type == 'osd':
self.mgr.osd_service.create_from_spec(cast(DriveGroupSpec, spec))
# TODO: return True would result in a busy loop
@ -552,12 +541,8 @@ class CephadmServe:
prefix=spec.service_id,
forcename=name)
if not did_config and config_func:
if daemon_type == 'rgw':
rgw_config_func = cast(Callable[[RGWSpec, str], None], config_func)
rgw_config_func(cast(RGWSpec, spec), daemon_id)
else:
config_func(spec)
if not did_config:
self.mgr.cephadm_services[service_type].config(spec, daemon_id)
did_config = True
daemon_spec = self.mgr.cephadm_services[service_type].make_daemon_spec(

View File

@ -124,6 +124,13 @@ class CephadmService(metaclass=ABCMeta):
def generate_config(self, daemon_spec: CephadmDaemonSpec) -> Tuple[Dict[str, Any], List[str]]:
raise NotImplementedError()
def config(self, spec: ServiceSpec, daemon_id: str) -> None:
"""
Configure the cluster for this service. Only called *once* per
service apply. Not for every daemon.
"""
pass
def daemon_check_post(self, daemon_descrs: List[DaemonDescription]) -> None:
"""The post actions needed to be done after daemons are checked"""
if self.mgr.config_dashboard:
@ -560,7 +567,7 @@ class MgrService(CephService):
class MdsService(CephService):
TYPE = 'mds'
def config(self, spec: ServiceSpec) -> None:
def config(self, spec: ServiceSpec, daemon_id: str) -> None:
assert self.TYPE == spec.service_type
assert spec.service_id
@ -616,7 +623,7 @@ class MdsService(CephService):
class RgwService(CephService):
TYPE = 'rgw'
def config(self, spec: RGWSpec, rgw_id: str) -> None:
def config(self, spec: RGWSpec, rgw_id: str) -> None: # type: ignore
assert self.TYPE == spec.service_type
# create realm, zonegroup, and zone if needed

View File

@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
class IscsiService(CephService):
TYPE = 'iscsi'
def config(self, spec: IscsiServiceSpec) -> None:
def config(self, spec: IscsiServiceSpec, daemon_id: str) -> None: # type: ignore
assert self.TYPE == spec.service_type
assert spec.pool
self.mgr._check_pool_exists(spec.pool, spec.service_name())

View File

@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
class NFSService(CephService):
TYPE = 'nfs'
def config(self, spec: NFSServiceSpec) -> None:
def config(self, spec: NFSServiceSpec, daemon_id: str) -> None: # type: ignore
assert self.TYPE == spec.service_type
assert spec.pool
self.mgr._check_pool_exists(spec.pool, spec.service_name())