Skip to content

Commit

Permalink
Update based on review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
weiiwang01 committed Oct 18, 2023
1 parent 43db0a0 commit 49ef065
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/charms/traefik_k8s/v2/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ class IngressRequirerUnitData(DatabagModel):
"""Ingress requirer unit databag model."""

host: str = Field(description="Hostname at which the unit is reachable.")
ip: Optional[str] = Field(description="IP at which the unit is reachable.")
ip: Optional[str] = Field(
description="IP at which the unit is reachable, "
"IP can only be None if the IP information can't be retrieved from juju."
)

@validator("host", pre=True)
def validate_host(cls, host): # noqa: N805 # pydantic wants 'cls' as first arg
Expand All @@ -207,7 +210,8 @@ def validate_ip(cls, ip): # noqa: N805 # pydantic wants 'cls' as first arg
"""Validate ip."""
if ip is None:
return None
assert isinstance(ip, str), type(ip)
if not isinstance(ip, str):
raise TypeError(f"got ip of type {type(ip)} instead of expected str")
try:
ipaddress.IPv4Address(ip)
return ip
Expand Down Expand Up @@ -683,8 +687,10 @@ def _publish_unit_data(
if network_binding is None:
ip = None
else:
binding_ip = network_binding.network.bind_address
if binding_ip is None:
if (
network_binding is None
or (binding_ip := network_binding.network.bind_address) is None
):
ip = None
else:
ip = str(binding_ip)
Expand Down

0 comments on commit 49ef065

Please sign in to comment.