diff --git a/src/charm.py b/src/charm.py index afc46729d9..8d9d532026 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1724,6 +1724,12 @@ def update_config(self, is_creating_backup: bool = False) -> bool: return True if not self._patroni.member_started: + if enable_tls: + logger.debug( + "Early exit update_config: patroni not responding but TLS is enabled." + ) + self._handle_postgresql_restart_need(True) + return True logger.debug("Early exit update_config: Patroni not started yet") return False @@ -1780,8 +1786,14 @@ def _validate_config_options(self) -> None: def _handle_postgresql_restart_need(self, enable_tls: bool) -> None: """Handle PostgreSQL restart need based on the TLS configuration and configuration changes.""" - restart_postgresql = self.is_tls_enabled != self.postgresql.is_tls_enabled() - self._patroni.reload_patroni_configuration() + if self._can_connect_to_postgresql: + restart_postgresql = self.is_tls_enabled != self.postgresql.is_tls_enabled() + else: + restart_postgresql = False + try: + self._patroni.reload_patroni_configuration() + except Exception as e: + logger.error(f"Reload patroni call failed! error: {e!s}") # Wait for some more time than the Patroni's loop_wait default value (10 seconds), # which tells how much time Patroni will wait before checking the configuration # file again to reload it. diff --git a/src/cluster.py b/src/cluster.py index 374964a5e5..463a44853d 100644 --- a/src/cluster.py +++ b/src/cluster.py @@ -791,7 +791,7 @@ def remove_raft_member(self, member_ip: str) -> None: if not result.startswith("SUCCESS"): raise RemoveRaftMemberFailedError() - @retry(stop=stop_after_attempt(10), wait=wait_exponential(multiplier=1, min=2, max=10)) + @retry(stop=stop_after_attempt(20), wait=wait_exponential(multiplier=1, min=2, max=10)) def reload_patroni_configuration(self): """Reload Patroni configuration after it was changed.""" requests.post( diff --git a/tests/unit/test_charm.py b/tests/unit/test_charm.py index 650dbe689d..9b38d7ec3e 100644 --- a/tests/unit/test_charm.py +++ b/tests/unit/test_charm.py @@ -1338,6 +1338,7 @@ def test_update_config(harness): harness.update_relation_data( rel_id, harness.charm.unit.name, {"tls": ""} ) # Mock some data in the relation to test that it doesn't change. + _is_tls_enabled.return_value = False harness.charm.update_config() _handle_postgresql_restart_need.assert_not_called() assert "tls" not in harness.get_relation_data(rel_id, harness.charm.unit.name)