mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-26 23:50:23 +00:00
Reload Consul config on SIGHUP (#1030)
It is especially useful when somebody is changing the value of `token`
This commit is contained in:
committed by
Alexander Kukushkin
parent
0e0b364302
commit
74893e7b84
+14
-3
@@ -122,7 +122,7 @@ class ConsulClient(base.Consul):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._cert = kwargs.pop('cert', None)
|
||||
self._ca_cert = kwargs.pop('ca_cert', None)
|
||||
self._token = kwargs.get('token')
|
||||
self.token = kwargs.get('token')
|
||||
super(ConsulClient, self).__init__(*args, **kwargs)
|
||||
|
||||
def connect(self, *args, **kwargs):
|
||||
@@ -131,10 +131,14 @@ class ConsulClient(base.Consul):
|
||||
kwargs['cert'] = self._cert
|
||||
if self._ca_cert:
|
||||
kwargs['ca_cert'] = self._ca_cert
|
||||
if self._token:
|
||||
kwargs['token'] = self._token
|
||||
if self.token:
|
||||
kwargs['token'] = self.token
|
||||
return HTTPClient(**kwargs)
|
||||
|
||||
def set_token(self, token):
|
||||
self.token = token
|
||||
self.http.token = self.token
|
||||
|
||||
|
||||
def catch_consul_errors(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
@@ -232,6 +236,13 @@ class Consul(AbstractDCS):
|
||||
logger.info('waiting on consul')
|
||||
time.sleep(5)
|
||||
|
||||
def reload_config(self, config):
|
||||
consul = config.get('consul')
|
||||
if consul:
|
||||
self._client.set_token(consul.get('token'))
|
||||
|
||||
super(Consul, self).reload_config(config)
|
||||
|
||||
def set_ttl(self, ttl):
|
||||
if self._client.http.set_ttl(ttl/2.0): # Consul multiplies the TTL by 2x
|
||||
self._session = None
|
||||
|
||||
Reference in New Issue
Block a user