diff --git a/src/machine_charm.py b/src/machine_charm.py index bbcdb5b8..7bb75d49 100755 --- a/src/machine_charm.py +++ b/src/machine_charm.py @@ -59,9 +59,6 @@ def __init__(self, *args) -> None: self.framework.observe( self.on[machine_upgrade.FORCE_ACTION_NAME].action, self._on_force_upgrade_action ) - self.framework.observe( - self.on[relations.hacluster.HACLUSTER_RELATION_NAME].relation_changed, self.reconcile - ) self.framework.observe(self.on.config_changed, self.reconcile) @property @@ -89,7 +86,11 @@ def _logrotate(self) -> machine_logrotate.LogRotate: @property def host_address(self) -> str: """The host address for the machine.""" - if self._ha_cluster.relation and self.config.get("vip"): + if ( + self._ha_cluster.relation + and self._ha_cluster._is_clustered() + and self.config.get("vip") + ): return self.config["vip"] return str(self.model.get_binding("juju-info").network.bind_address) diff --git a/src/relations/database_provides.py b/src/relations/database_provides.py index 04d5e6a7..1d5666a4 100644 --- a/src/relations/database_provides.py +++ b/src/relations/database_provides.py @@ -170,6 +170,9 @@ def update_endpoints( exposed_read_only_endpoint: str, ) -> None: """Update the endpoints in the databag.""" + logger.debug( + f"Updating endpoints {self._id} {router_read_write_endpoint=}, {router_read_only_endpoint=} {exposed_read_write_endpoint=} {exposed_read_only_endpoint=}" + ) rw_endpoint = ( exposed_read_write_endpoint if self.external_connectivity @@ -181,6 +184,9 @@ def update_endpoints( self._interface.set_endpoints(self._id, rw_endpoint) self._interface.set_read_only_endpoints(self._id, ro_endpoint) + logger.debug( + f"Updated endpoints {self._id} {router_read_write_endpoint=}, {router_read_only_endpoint=} {exposed_read_write_endpoint=} {exposed_read_only_endpoint=}" + ) def delete_databag(self) -> None: """Remove connection information from databag.""" @@ -248,10 +254,7 @@ def update_endpoints( exposed_read_write_endpoint: str, exposed_read_only_endpoint: str, ) -> None: - """Update the endpoints in the provides relationship databags.""" - logger.debug( - f"Update endpoints {router_read_write_endpoint=}, {router_read_only_endpoint=} {exposed_read_write_endpoint=} {exposed_read_only_endpoint=}" - ) + """Update endpoints in the databags.""" for relation in self._shared_users: relation.update_endpoints( router_read_write_endpoint=router_read_write_endpoint, diff --git a/src/relations/hacluster.py b/src/relations/hacluster.py index 29ed0615..70b076e7 100644 --- a/src/relations/hacluster.py +++ b/src/relations/hacluster.py @@ -25,6 +25,10 @@ def __init__(self, charm: ops.CharmBase): self.charm = charm + self.framework.observe( + self.charm.on[HACLUSTER_RELATION_NAME].relation_changed, self.charm.reconcile + ) + @property def relation(self) -> Optional[ops.Relation]: """Returns the relations in this model, or None if hacluster is not initialised.""" @@ -33,10 +37,12 @@ def relation(self) -> Optional[ops.Relation]: def _is_clustered(self) -> bool: """Check if the related hacluster charm is clustered.""" for key, value in self.relation.data.items(): - if isinstance(key, ops.Unit) and key != self.charm.unit: - if value.get("clustered") in ("yes", "true"): - return True - break + if ( + isinstance(key, ops.Unit) + and key != self.charm.unit + and value.get("clustered") in ("yes", "true") + ): + return True return False def get_unit_juju_status(self) -> ops.StatusBase: