Skip to content

Commit

Permalink
Remove retry on lb response
Browse files Browse the repository at this point in the history
  • Loading branch information
HomayoonAlimohammadi committed Jan 8, 2025
1 parent 9ba42f7 commit 78fef20
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions charms/worker/k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,18 @@ def _check_k8sd_ready(self):
self.api_manager.check_k8sd_ready()

def _get_extra_sans(self):
"""Retrieve the certificate extra SANs."""
"""Retrieve the certificate extra SANs.
Raises:
ReconcilerError: If the public address cannot be retrieved.
"""
extra_sans_str = str(self.config.get("kube-apiserver-extra-sans") or "")
extra_sans = {san for san in extra_sans_str.strip().split() if san}
if public_address := self._get_public_address():
log.info("Public address %s found, adding it to extra SANs", public_address)
extra_sans.add(public_address)
else:
log.info("No public address found, skipping adding public address to extra SANs")
raise ReconcilerError("Failed to get public address")
return sorted(extra_sans)

def _assemble_bootstrap_config(self):
Expand Down Expand Up @@ -428,33 +432,7 @@ def _configure_external_load_balancer(self):
if not req.health_checks:
req.add_health_check(protocol=req.protocols.http, port=APISERVER_PORT, path="/livez")
self.external_load_balancer.send_request(req)

# wait for response
retry_interval_seconds = 3
retries = 10
for _ in range(retries):
res = self.external_load_balancer.get_response(EXTERNAL_LOAD_BALANCER_RESPONSE_NAME)
if res is None:
log.info(
"Waiting for external load balancer response. Retrying in %s seconds",
retry_interval_seconds,
)
sleep(retry_interval_seconds)
continue
if res.error_message:
log.error("Error from external load balancer: %s", res.error_message)
raise ReconcilerError(
"Failed to configure external load balancer. Check logs for details"
)

log.info("External load balancer response received: %s", res)
return

log.error(
"Timed out waiting for external load balancer response after %s seconds",
retry_interval_seconds * retries,
)
raise ReconcilerError("External load balancer response not received")
log.info("External load balancer request was sent")

@on_error(
ops.WaitingStatus("Waiting to bootstrap k8s snap"),
Expand Down Expand Up @@ -1136,7 +1114,8 @@ def _get_external_kubeconfig(self, event: ops.ActionEvent):
log.info("No server requested, use public address")
server = self._get_public_address()
if not server:
log.info("No public address found")
event.fail("Failed to get public address. Check logs for details.")
return
else:
log.info("Found public address: %s", server)
port = str(APISERVER_PORT)
Expand Down

0 comments on commit 78fef20

Please sign in to comment.