@@ -819,30 +819,33 @@ def _get_security_config(self) -> Tuple[bool, bool, bool]:
819819 security_enabled = self .secure_monitoring_stack or mgmt_gw_enabled
820820 return security_enabled , mgmt_gw_enabled , oauth2_proxy_enabled
821821
822- def get_mgmt_gw_internal_endpoint (self ) -> Optional [str ]:
822+ def _get_mgmt_gw_endpoint (self , is_internal : bool ) -> Optional [str ]:
823823 mgmt_gw_daemons = self .cache .get_daemons_by_service ('mgmt-gateway' )
824824 if not mgmt_gw_daemons :
825825 return None
826826
827827 dd = mgmt_gw_daemons [0 ]
828828 assert dd .hostname is not None
829- mgmt_gw_addr = self .get_fqdn (dd .hostname )
830- mgmt_gw_internal_endpoint = build_url (scheme = 'https' , host = mgmt_gw_addr , port = MgmtGatewayService .INTERNAL_SERVICE_PORT )
831- return f'{ mgmt_gw_internal_endpoint } /internal'
829+ mgmt_gw_spec = cast (MgmtGatewaySpec , self .spec_store ['mgmt-gateway' ].spec )
830+ mgmt_gw_addr = mgmt_gw_spec .virtual_ip if mgmt_gw_spec .virtual_ip is not None else self .get_fqdn (dd .hostname )
832831
833- def get_mgmt_gw_external_endpoint (self ) -> Optional [str ]:
834- mgmt_gw_daemons = self .cache .get_daemons_by_service ('mgmt-gateway' )
835- if not mgmt_gw_daemons :
836- return None
832+ if is_internal :
833+ mgmt_gw_port : Optional [int ] = MgmtGatewayService .INTERNAL_SERVICE_PORT
834+ protocol = 'https'
835+ endpoint_suffix = '/internal'
836+ else :
837+ mgmt_gw_port = dd .ports [0 ] if dd .ports else None
838+ protocol = 'http' if mgmt_gw_spec .disable_https else 'https'
839+ endpoint_suffix = ''
837840
838- dd = mgmt_gw_daemons [ 0 ]
839- assert dd . hostname is not None
840- mgmt_gw_port = dd . ports [ 0 ] if dd . ports else None
841- mgmt_gw_addr = self . get_fqdn ( dd . hostname )
842- mgmt_gw_spec = cast ( MgmtGatewaySpec , self .spec_store [ 'mgmt-gateway' ]. spec )
843- protocol = 'http' if mgmt_gw_spec . disable_https else 'https'
844- mgmt_gw_external_endpoint = build_url ( scheme = protocol , host = mgmt_gw_addr , port = mgmt_gw_port )
845- return mgmt_gw_external_endpoint
841+ mgmt_gw_endpoint = build_url ( scheme = protocol , host = mgmt_gw_addr , port = mgmt_gw_port )
842+ return f' { mgmt_gw_endpoint } { endpoint_suffix } '
843+
844+ def get_mgmt_gw_internal_endpoint ( self ) -> Optional [ str ]:
845+ return self ._get_mgmt_gw_endpoint ( is_internal = True )
846+
847+ def get_mgmt_gw_external_endpoint ( self ) -> Optional [ str ]:
848+ return self . _get_mgmt_gw_endpoint ( is_internal = False )
846849
847850 def _get_cephadm_binary_path (self ) -> str :
848851 import hashlib
@@ -3001,8 +3004,16 @@ def get_daemon_names(daemons: List[str]) -> List[str]:
30013004 daemon_names .append (dd .name ())
30023005 return daemon_names
30033006
3004- alertmanager_user , alertmanager_password = self ._get_alertmanager_credentials ()
3005- prometheus_user , prometheus_password = self ._get_prometheus_credentials ()
3007+ prom_cred_hash = None
3008+ alertmgr_cred_hash = None
3009+ security_enabled , mgmt_gw_enabled , _ = self ._get_security_config ()
3010+ if security_enabled :
3011+ alertmanager_user , alertmanager_password = self ._get_alertmanager_credentials ()
3012+ prometheus_user , prometheus_password = self ._get_prometheus_credentials ()
3013+ if prometheus_user and prometheus_password :
3014+ prom_cred_hash = f'{ utils .md5_hash (prometheus_user + prometheus_password )} '
3015+ if alertmanager_user and alertmanager_password :
3016+ alertmgr_cred_hash = f'{ utils .md5_hash (alertmanager_user + alertmanager_password )} '
30063017
30073018 deps = []
30083019 if daemon_type == 'haproxy' :
@@ -3049,9 +3060,10 @@ def get_daemon_names(daemons: List[str]) -> List[str]:
30493060 else :
30503061 deps = [self .get_mgr_ip ()]
30513062 elif daemon_type == 'prometheus' :
3052- # for prometheus we add the active mgr as an explicit dependency,
3053- # this way we force a redeploy after a mgr failover
3054- deps .append (self .get_active_mgr ().name ())
3063+ if not mgmt_gw_enabled :
3064+ # for prometheus we add the active mgr as an explicit dependency,
3065+ # this way we force a redeploy after a mgr failover
3066+ deps .append (self .get_active_mgr ().name ())
30553067 deps .append (str (self .get_module_option_ex ('prometheus' , 'server_port' , 9283 )))
30563068 deps .append (str (self .service_discovery_port ))
30573069 # prometheus yaml configuration file (generated by prometheus.yml.j2) contains
@@ -3068,22 +3080,20 @@ def get_daemon_names(daemons: List[str]) -> List[str]:
30683080 deps += [d .name () for d in self .cache .get_daemons_by_service ('ceph-exporter' )]
30693081 deps += [d .name () for d in self .cache .get_daemons_by_service ('mgmt-gateway' )]
30703082 deps += [d .name () for d in self .cache .get_daemons_by_service ('oauth2-proxy' )]
3071- security_enabled , _ , _ = self ._get_security_config ()
3072- if security_enabled :
3073- if prometheus_user and prometheus_password :
3074- deps .append (f'{ hash (prometheus_user + prometheus_password )} ' )
3075- if alertmanager_user and alertmanager_password :
3076- deps .append (f'{ hash (alertmanager_user + alertmanager_password )} ' )
3083+ if prom_cred_hash is not None :
3084+ deps .append (prom_cred_hash )
3085+ if alertmgr_cred_hash is not None :
3086+ deps .append (alertmgr_cred_hash )
30773087 elif daemon_type == 'grafana' :
30783088 deps += get_daemon_names (['prometheus' , 'loki' , 'mgmt-gateway' , 'oauth2-proxy' ])
3079- security_enabled , _ , _ = self ._get_security_config ()
3080- if security_enabled and prometheus_user and prometheus_password :
3081- deps .append (f'{ hash (prometheus_user + prometheus_password )} ' )
3089+ if prom_cred_hash is not None :
3090+ deps .append (prom_cred_hash )
30823091 elif daemon_type == 'alertmanager' :
3083- deps += get_daemon_names (['mgr' , 'alertmanager' , 'snmp-gateway' , 'mgmt-gateway' , 'oauth2-proxy' ])
3084- security_enabled , _ , _ = self ._get_security_config ()
3085- if security_enabled and alertmanager_user and alertmanager_password :
3086- deps .append (f'{ hash (alertmanager_user + alertmanager_password )} ' )
3092+ deps += get_daemon_names (['alertmanager' , 'snmp-gateway' , 'mgmt-gateway' , 'oauth2-proxy' ])
3093+ if not mgmt_gw_enabled :
3094+ deps += get_daemon_names (['mgr' ])
3095+ if alertmgr_cred_hash is not None :
3096+ deps .append (alertmgr_cred_hash )
30873097 elif daemon_type == 'promtail' :
30883098 deps += get_daemon_names (['loki' ])
30893099 elif daemon_type in ['ceph-exporter' , 'node-exporter' ]:
@@ -3097,7 +3107,7 @@ def get_daemon_names(daemons: List[str]) -> List[str]:
30973107 elif daemon_type == 'mgmt-gateway' :
30983108 # url_prefix for monitoring daemons depends on the presence of mgmt-gateway
30993109 # while dashboard urls depend on the mgr daemons
3100- deps += get_daemon_names (['mgr' , ' grafana' , 'prometheus' , 'alertmanager' , 'oauth2-proxy' ])
3110+ deps += get_daemon_names (['grafana' , 'prometheus' , 'alertmanager' , 'oauth2-proxy' ])
31013111 else :
31023112 # this daemon type doesn't need deps mgmt
31033113 pass
0 commit comments