From 4c534ec0d744fcc27454b95c68c8322687235f27 Mon Sep 17 00:00:00 2001 From: Shayan Patel Date: Tue, 1 Oct 2024 13:13:57 +0000 Subject: [PATCH 1/4] Always return VIP as host if set --- src/machine_charm.py | 6 +----- src/relations/hacluster.py | 8 +------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/machine_charm.py b/src/machine_charm.py index 788823b5..0123e1f7 100755 --- a/src/machine_charm.py +++ b/src/machine_charm.py @@ -86,11 +86,7 @@ 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._ha_cluster.is_clustered() - and self.config.get("vip") - ): + if self.config.get("vip"): return self.config["vip"] return str(self.model.get_binding("juju-info").network.bind_address) diff --git a/src/relations/hacluster.py b/src/relations/hacluster.py index de4ea9d6..bd11be5e 100644 --- a/src/relations/hacluster.py +++ b/src/relations/hacluster.py @@ -10,8 +10,6 @@ import ops -import workload - HACLUSTER_RELATION_NAME = "ha" logger = logging.getLogger(__name__) @@ -57,11 +55,7 @@ def get_unit_juju_status(self) -> ops.StatusBase: if vip and not self.charm.is_externally_accessible(event=None): return ops.BlockedStatus("vip configuration without data-integrator") - if ( - isinstance(self.charm.get_workload(event=None), workload.AuthenticatedWorkload) - and self.charm.unit.is_leader() - and vip - ): + if self.charm.unit.is_leader() and vip: return ops.ActiveStatus(f"VIP: {vip}") def set_vip(self, vip: Optional[str]) -> None: From 586bb4ad84c3527109c067ee9ef19b265b2bda89 Mon Sep 17 00:00:00 2001 From: Shayan Patel Date: Tue, 1 Oct 2024 13:15:49 +0000 Subject: [PATCH 2/4] Report host as configured VIP if the charm is externally connected --- src/machine_charm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/machine_charm.py b/src/machine_charm.py index 0123e1f7..0609cc61 100755 --- a/src/machine_charm.py +++ b/src/machine_charm.py @@ -86,7 +86,7 @@ def _logrotate(self) -> machine_logrotate.LogRotate: @property def host_address(self) -> str: """The host address for the machine.""" - if self.config.get("vip"): + if self.is_externally_accessible(event=None) and self.config.get("vip"): return self.config["vip"] return str(self.model.get_binding("juju-info").network.bind_address) From 03c5777be3d34226d8120fb7503fef63b61dd1bb Mon Sep 17 00:00:00 2001 From: Shayan Patel Date: Wed, 2 Oct 2024 13:40:03 +0000 Subject: [PATCH 3/4] If relation with ha cluster, ensure ha cluster is clustered before providing VIP as endpoint --- src/machine_charm.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/machine_charm.py b/src/machine_charm.py index 0609cc61..b0e09713 100755 --- a/src/machine_charm.py +++ b/src/machine_charm.py @@ -86,9 +86,14 @@ def _logrotate(self) -> machine_logrotate.LogRotate: @property def host_address(self) -> str: """The host address for the machine.""" - if self.is_externally_accessible(event=None) and self.config.get("vip"): - return self.config["vip"] - return str(self.model.get_binding("juju-info").network.bind_address) + if ( + not self.is_externally_accessible(event=None) + or not self.config.get("vip") + or (self._ha_cluster and not self._ha_cluster.is_clustered()) + ): + return str(self.model.get_binding("juju-info").network.bind_address) + + return self.config["vip"] @property def _read_write_endpoint(self) -> str: From 49ce2289d8c27208cb90aa037c19a27deeaa9360 Mon Sep 17 00:00:00 2001 From: Shayan Patel Date: Wed, 16 Oct 2024 19:58:24 +0000 Subject: [PATCH 4/4] Address PR feedback --- src/relations/hacluster.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/relations/hacluster.py b/src/relations/hacluster.py index bd11be5e..cf1f3906 100644 --- a/src/relations/hacluster.py +++ b/src/relations/hacluster.py @@ -34,6 +34,9 @@ def relation(self) -> Optional[ops.Relation]: def is_clustered(self) -> bool: """Check if the related hacluster charm is clustered.""" + if not self.relation: + return False + for key, value in self.relation.data.items(): if ( isinstance(key, ops.Unit) @@ -55,9 +58,6 @@ def get_unit_juju_status(self) -> ops.StatusBase: if vip and not self.charm.is_externally_accessible(event=None): return ops.BlockedStatus("vip configuration without data-integrator") - if self.charm.unit.is_leader() and vip: - return ops.ActiveStatus(f"VIP: {vip}") - def set_vip(self, vip: Optional[str]) -> None: """Adds the requested virtual IP to the integration.""" if not self.relation: