Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle None being returned for ingresses #353

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions charms/istio-pilot/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,11 +827,10 @@ def _get_address_from_loadbalancer(svc):
(str): The hostname or IP address of the LoadBalancer service
"""
ingresses = svc.status.loadBalancer.ingress
if len(ingresses) != 1:
if len(ingresses) == 0:
return None
else:
raise ValueError("Unknown situation - LoadBalancer service has more than one ingress")
if ingresses is None or len(ingresses) == 0:
return None
elif len(ingresses) != 1:
raise ValueError("Unknown situation - LoadBalancer service has more than one ingress")

ingress = svc.status.loadBalancer.ingress[0]
if getattr(ingress, "hostname", None) is not None:
Expand Down
14 changes: 14 additions & 0 deletions charms/istio-pilot/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def test_is_gateway_object_up(
("mock_loadbalancer_ip_service", True),
("mock_loadbalancer_hostname_service_not_ready", False),
("mock_loadbalancer_ip_service_not_ready", False),
("mock_loadbalancer_service_not_ready_returning_none_for_ingresses", False),
],
)
def test_is_gateway_service_up(
Expand Down Expand Up @@ -542,6 +543,7 @@ def test_is_gateway_service_up(
("mock_loadbalancer_ip_service", "127.0.0.1"),
("mock_loadbalancer_hostname_service_not_ready", None),
("mock_loadbalancer_ip_service_not_ready", None),
("mock_loadbalancer_service_not_ready_returning_none_for_ingresses", None),
],
)
def test_get_gateway_address_from_svc(
Expand Down Expand Up @@ -1435,6 +1437,18 @@ def mock_loadbalancer_hostname_service_not_ready():
)
return mock_nodeport_service

@pytest.fixture()
def mock_loadbalancer_service_not_ready_returning_none_for_ingresses():
mock_nodeport_service = codecs.from_dict(
{
"apiVersion": "v1",
"kind": "Service",
"status": {"loadBalancer": {"ingress": None}},
"spec": {"type": "LoadBalancer", "clusterIP": "10.10.10.10"},
}
)
return mock_nodeport_service


# autouse to ensure we don't accidentally call out, but
# can also be used explicitly to get access to the mock.
Expand Down
Loading