Skip to content

Commit

Permalink
Address another round of feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
shayancanonical committed Sep 23, 2024
1 parent adf5839 commit 9649f9e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/machine_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 7 additions & 4 deletions src/relations/database_provides.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 10 additions & 4 deletions src/relations/hacluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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:
Expand Down

0 comments on commit 9649f9e

Please sign in to comment.