Skip to content

Commit c2e940f

Browse files
Always return VIP as host if set (#179)
## Issue We would like to always return the configured VIP as the host when externally connected (to support use cases where the VIP may be configured outside of the charms e.g. openstack octavia) ## Solution Update the conditions that 1. Report host as configured VIP if externally accessible 2. Set active status on the unit if the charm is the leader and VIP is configured (and prior compatibility checks run - i.e. charm is externally accessible when related to hacluster + charm has a VIP if related to hacluster + VIP is configured only when related to data-integrator) ## Reference PGBouncer charm has the above described functionality: https://github.com/canonical/pgbouncer-operator/pull/337/files#diff-b9ed39bbc9c0387bd3e07da31d13373745534a1cd723d3e292c73496b12e307cR551
1 parent f163917 commit c2e940f

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/charm.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ def _logrotate(self) -> machine_logrotate.LogRotate:
9797
def host_address(self) -> str:
9898
"""The host address for the machine."""
9999
if (
100-
self._ha_cluster.relation
101-
and self._ha_cluster.is_clustered()
102-
and self.config.get("vip")
100+
not self.is_externally_accessible(event=None)
101+
or not self.config.get("vip")
102+
or (self._ha_cluster and not self._ha_cluster.is_clustered())
103103
):
104-
return self.config["vip"]
105-
return str(self.model.get_binding("juju-info").network.bind_address)
104+
return str(self.model.get_binding("juju-info").network.bind_address)
105+
106+
return self.config["vip"]
106107

107108
@property
108109
def _read_write_endpoints(self) -> str:

src/relations/hacluster.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
import ops
1212

13-
import workload
14-
1513
HACLUSTER_RELATION_NAME = "ha"
1614

1715
logger = logging.getLogger(__name__)
@@ -36,6 +34,9 @@ def relation(self) -> Optional[ops.Relation]:
3634

3735
def is_clustered(self) -> bool:
3836
"""Check if the related hacluster charm is clustered."""
37+
if not self.relation:
38+
return False
39+
3940
for key, value in self.relation.data.items():
4041
if (
4142
isinstance(key, ops.Unit)
@@ -57,13 +58,6 @@ def get_unit_juju_status(self) -> ops.StatusBase:
5758
if vip and not self.charm.is_externally_accessible(event=None):
5859
return ops.BlockedStatus("vip configuration without data-integrator")
5960

60-
if (
61-
isinstance(self.charm.get_workload(event=None), workload.AuthenticatedWorkload)
62-
and self.charm.unit.is_leader()
63-
and vip
64-
):
65-
return ops.ActiveStatus(f"VIP: {vip}")
66-
6761
def set_vip(self, vip: Optional[str]) -> None:
6862
"""Adds the requested virtual IP to the integration."""
6963
if not self.relation:

0 commit comments

Comments
 (0)