From 35c97fa402ad2ff135493dfcb1c58e7169041794 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Mon, 10 Jul 2023 09:19:10 +0200 Subject: [PATCH] Make sure the version_prefix for etcd3 is set to /v3beta (#2729) Setting it before calling the parent constructor didn't really work because it is being overwritten in the `etcd.Client.__init__()`. The only viable way of doing it is passing a custom value to the parent class. Close https://github.com/zalando/patroni/issues/2142 --- patroni/dcs/etcd.py | 5 ++++- patroni/dcs/etcd3.py | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/patroni/dcs/etcd.py b/patroni/dcs/etcd.py index 3e7f0681..5f667771 100644 --- a/patroni/dcs/etcd.py +++ b/patroni/dcs/etcd.py @@ -99,7 +99,7 @@ class AbstractEtcdClientWithFailover(abc.ABC, etcd.Client): self._dns_resolver = dns_resolver self.set_machines_cache_ttl(cache_ttl) self._machines_cache_updated = 0 - kwargs = {p: config.get(p) for p in ('host', 'port', 'protocol', 'use_proxies', + kwargs = {p: config.get(p) for p in ('host', 'port', 'protocol', 'use_proxies', 'version_prefix', 'username', 'password', 'cert', 'ca_cert') if config.get(p)} super(AbstractEtcdClientWithFailover, self).__init__(read_timeout=config['retry_timeout'], **kwargs) # For some reason python3-etcd on debian and ubuntu are not based on the latest version @@ -443,6 +443,9 @@ class EtcdClient(AbstractEtcdClientWithFailover): ERROR_CLS = EtcdError + def __init__(self, config: Dict[str, Any], dns_resolver: DnsCachingResolver, cache_ttl: int = 300) -> None: + super(EtcdClient, self).__init__({**config, 'version_prefix': None}, dns_resolver, cache_ttl) + def __del__(self) -> None: try: self.http.clear() diff --git a/patroni/dcs/etcd3.py b/patroni/dcs/etcd3.py index b89e36a5..efb955e0 100644 --- a/patroni/dcs/etcd3.py +++ b/patroni/dcs/etcd3.py @@ -206,8 +206,7 @@ class Etcd3Client(AbstractEtcdClientWithFailover): def __init__(self, config: Dict[str, Any], dns_resolver: DnsCachingResolver, cache_ttl: int = 300) -> None: self._token = None self._cluster_version: Tuple[int] = tuple() - self.version_prefix = '/v3beta' - super(Etcd3Client, self).__init__(config, dns_resolver, cache_ttl) + super(Etcd3Client, self).__init__({**config, 'version_prefix': '/v3beta'}, dns_resolver, cache_ttl) try: self.authenticate()