Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
TRACING_PROTOCOL,
TRACING_RELATION_NAME,
)
from k8s_helpers import KubernetesHelpers
from k8s_helpers import KubernetesHelpers, k8s_domain
from log_rotate_manager import LogRotateManager
from mysql_k8s_helpers import MySQL, MySQLInitialiseMySQLDError
from relations.mysql import MySQLRelation
Expand Down Expand Up @@ -351,23 +351,7 @@ def get_unit_address(self, unit: Unit, relation_name: str = PEER) -> str:
Translate juju unit name to resolvable hostname.
"""
unit_hostname = self.get_unit_hostname(unit.name)
unit_dns_domain = getfqdn(self.get_unit_hostname(unit.name))

# When fully propagated, DNS domain name should contain unit hostname.
# For example:
# Hostname: mysql-k8s-0.mysql-k8s-endpoints
# Fully propagated: mysql-k8s-0.mysql-k8s-endpoints.dev.svc.cluster.local
# Not propagated yet: 10-1-142-191.mysql-k8s.dev.svc.cluster.local
if unit_hostname not in unit_dns_domain:
logger.warning(
"get_unit_address: unit DNS domain name is not fully propagated yet, trying again"
)
raise RuntimeError("unit DNS domain name is not fully propagated yet")
if unit_dns_domain == unit_hostname:
logger.warning("Can't get fully qualified domain name for unit. IS DNS not ready?")
raise RuntimeError("Can't get unit fqdn")

return dotappend(unit_dns_domain)
return dotappend(f"{unit_hostname}.{self.model.name}.svc.{k8s_domain()}")

def is_unit_busy(self) -> bool:
"""Returns whether the unit is busy."""
Expand Down
5 changes: 5 additions & 0 deletions src/k8s_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
from charm import MySQLOperatorCharm


def k8s_domain() -> str:
"""Return the Kubernetes domain."""
return socket.getfqdn("kubernetes.default").split(".svc.")[-1]
Comment on lines +32 to +33
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why split on .svc.? is socket.getfqdn not give us the fqdn?



class KubernetesClientError(Exception):
"""Exception raised when client can't execute."""

Expand Down
Loading