From 9015edc3f34bbaf1906b9e5c83be7c49ef7c42c8 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Wed, 27 Sep 2023 18:30:17 -0400 Subject: [PATCH] cephadm: convert monitoring type to a ContainerDaemonForm Signed-off-by: John Mulligan --- src/cephadm/cephadm.py | 66 +++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 403575f0bf4b7..6c87d7983b6fc 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -422,7 +422,7 @@ class SNMPGateway(ContainerDaemonForm): ################################## @register_daemon_form -class Monitoring(DaemonForm): +class Monitoring(ContainerDaemonForm): """Define the configs for the monitoring containers""" port_map = { @@ -574,6 +574,42 @@ class Monitoring(DaemonForm): def identity(self) -> DaemonIdentity: return self._identity + def container(self, ctx: CephadmContext) -> CephContainer: + self._prevalidate(ctx) + return get_deployment_container(ctx, self.identity) + + def uid_gid(self, ctx: CephadmContext) -> Tuple[int, int]: + return self.extract_uid_gid(ctx, self.identity.daemon_type) + + def _prevalidate(self, ctx: CephadmContext) -> None: + # before being refactored into a ContainerDaemonForm these checks were + # done inside the deploy function. This was the only "family" of daemons + # that performed these checks in that location + daemon_type = self.identity.daemon_type + config = fetch_configs(ctx) # type: ignore + required_files = self.components[daemon_type].get( + 'config-json-files', list() + ) + required_args = self.components[daemon_type].get( + 'config-json-args', list() + ) + if required_files: + if not config or not all(c in config.get('files', {}).keys() for c in required_files): # type: ignore + raise Error( + '{} deployment requires config-json which must ' + 'contain file content for {}'.format( + daemon_type.capitalize(), ', '.join(required_files) + ) + ) + if required_args: + if not config or not all(c in config.keys() for c in required_args): # type: ignore + raise Error( + '{} deployment requires config-json which must ' + 'contain arg for {}'.format( + daemon_type.capitalize(), ', '.join(required_args) + ) + ) + ################################## @@ -5190,34 +5226,6 @@ def _dispatch_deploy( endpoints=daemon_endpoints, ) - elif daemon_type in Monitoring.components: - # monitoring daemon - prometheus, grafana, alertmanager, node-exporter - # Default Checks - # make sure provided config-json is sufficient - config = fetch_configs(ctx) # type: ignore - required_files = Monitoring.components[daemon_type].get('config-json-files', list()) - required_args = Monitoring.components[daemon_type].get('config-json-args', list()) - if required_files: - if not config or not all(c in config.get('files', {}).keys() for c in required_files): # type: ignore - raise Error('{} deployment requires config-json which must ' - 'contain file content for {}'.format(daemon_type.capitalize(), ', '.join(required_files))) - if required_args: - if not config or not all(c in config.keys() for c in required_args): # type: ignore - raise Error('{} deployment requires config-json which must ' - 'contain arg for {}'.format(daemon_type.capitalize(), ', '.join(required_args))) - - uid, gid = Monitoring.extract_uid_gid(ctx, daemon_type) - c = get_deployment_container(ctx, ident) - deploy_daemon( - ctx, - ident, - c, - uid, - gid, - deployment_type=deployment_type, - endpoints=daemon_endpoints - ) - elif daemon_type == CephadmAgent.daemon_type: # get current user gid and uid uid = os.getuid() -- 2.39.5