Skip to content

Commit

Permalink
Merge pull request #89 from canonical/dnplas/gateway-fixes
Browse files Browse the repository at this point in the history
Small refactor on handle_ingress and _gateway_address
  • Loading branch information
ca-scribner authored May 6, 2022
2 parents a78e80d + cd5c8ba commit e4d5ab0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions charms/istio-pilot/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,26 @@ def send_info(self, event):

def handle_ingress(self, event):
try:
if not self._get_gateway_address:
if not self._gateway_address:
self.log.info(
"No gateway address returned - this may be transitory, but "
"if it persists it is likely an unexpected error. "
"Deferring this event"
)
self.unit.status = WaitingStatus("Waiting for gateway address")
event.defer()
return
except (ApiError, TypeError) as e:
if isinstance(e, ApiError):
self.log.exception(
"ApiError: Could not get istio-ingressgateway, deferring this event"
"ApiError: Could not get istio-ingressgateway-workload, deferring this event"
)
elif isinstance(e, TypeError):
self.log.exception("TypeError: No ip address found, deferring this event")
else:
self.log.exception("Unexpected exception, deferring this event. Exception was:")
self.log.exception(e)
self.unit.status = BlockedStatus("Missing istio-ingressgateway relation")
event.defer()
return

Expand Down Expand Up @@ -253,15 +255,15 @@ def handle_ingress_auth(self, event):
self._resource_handler.apply_manifest(auth_filters, namespace=self.model.name)

@property
def _get_gateway_address(self):
def _gateway_address(self):
"""Look up the load balancer address for the ingress gateway.
If the gateway isn't available or doesn't have a load balancer address yet,
returns None.
"""
# FIXME: service name is hardcoded
# TODO: extract this from charm code
svcs = self.lightkube_client.get(
Service, name="istio-ingressgateway", namespace=self.model.name
Service, name="istio-ingressgateway-workload", namespace=self.model.name
)
return svcs.status.loadBalancer.ingress[0].ip

Expand Down
4 changes: 2 additions & 2 deletions tests/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ async def test_deploy_istio_charms(ops_test: OpsTest):

await ops_test.model.wait_for_idle(
status="active",
raise_on_blocked=True,
timeout=60 * 10,
raise_on_blocked=False,
timeout=90 * 10,
)


Expand Down

0 comments on commit e4d5ab0

Please sign in to comment.