Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
HomayoonAlimohammadi committed Jan 6, 2025
1 parent da49e4c commit e3bc49e
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions charms/worker/k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def _get_extra_sans(self):
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(f"Public address {public_address} found, adding it to extra SANs")
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")
Expand Down Expand Up @@ -435,21 +435,23 @@ def _configure_external_load_balancer(self):
res = self.external_load_balancer.get_response(EXTERNAL_LOAD_BALANCER_RESPONSE_NAME)
if res is None:
log.info(
f"Waiting for external load balancer response. Retrying in {retry_interval_seconds}s"
"Waiting for external load balancer response. Retrying in %s seconds",
retry_interval_seconds,
)
sleep(retry_interval_seconds)
continue
if res.error_message:
log.error(f"Error from external load balancer: {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(f"External load balancer response received: {res}")
log.info("External load balancer response received: %s", res)
return

log.error(
f"Timedout waiting for external load balancer response after {retry_interval_seconds*retries}s"
"Timedout waiting for external load balancer response after %s seconds",
retry_interval_seconds * retries,
)
raise ReconcilerError("External load balancer response not received")

Expand Down Expand Up @@ -1135,13 +1137,13 @@ def _get_external_kubeconfig(self, event: ops.ActionEvent):
if not server:
log.info("No public address found")
else:
log.info(f"Found public address: {server}")
log.info("Found public address: %s", server)
port = str(APISERVER_PORT)
if self.is_control_plane and self.external_load_balancer.is_available:
log.info("Using external load balancer port as the public port")
port = str(self.config.get(EXTERNAL_LOAD_BALANCER_PORT_CONFIG))
server = self._format_kube_api_url(server, port)
log.info(f"Formatted server address: {server}")
log.info("Formatted server address: %s", server)
log.info("Requesting kubeconfig for server=%s", server)
resp = self.api_manager.get_kubeconfig(server)
event.set_results({"kubeconfig": resp})
Expand Down Expand Up @@ -1177,9 +1179,10 @@ def _get_external_load_balancer_address(self) -> Optional[str]:
if not response:
log.error("No response from external load balancer when trying to get address")
return None
elif response.error:
if response.error:
log.error(
f"Error from external load balancer when trying to get address: {response.error}"
"Error from external load balancer when trying to get address: %s",
response.error,
)
return None

Expand All @@ -1198,10 +1201,10 @@ def _format_kube_api_url(self, addr: str, port: str) -> str:
addr = addr.lower()
default_scheme = "https://"
if not addr.startswith(default_scheme) and not addr.startswith("http://"):
log.info(f"Adding {default_scheme} to {addr=}")
log.info("Adding %s to addr %s", default_scheme, addr)
addr = default_scheme + addr
if re.search(ENDPOINT_HAS_PORT_REGEX, addr) is None:
log.info(f"Adding {port=} to {addr=}")
log.info("Adding port %s to addr %s", port, addr)
addr = f"{addr}:{port}"
return addr

Expand Down

0 comments on commit e3bc49e

Please sign in to comment.