Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Aug 12, 2024
1 parent 6141475 commit 1cdcd56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions charms/worker/k8s/lib/charms/k8s/v0/k8sd_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,15 +782,17 @@ def check_k8sd_ready(self):
K8sdConnectionError: If the response is Not Found on all endpoints.
"""
ready_endpoints = ["/core/1.0/ready", "/cluster/1.0/ready"]
for endpoint in ready_endpoints:
for i, endpoint in enumerate(ready_endpoints):
try:
self._send_request(endpoint, "GET", EmptyResponse)
break
except InvalidResponseError as ex:
if ex.code == 404:
logger.warning(
"Encountered 404 while checking if micro-cluster is ready @ %s: %s",
"micro-cluster unavailable @ %s (%s of %s): %s",
endpoint,
i + 1,
len(ready_endpoints),
ex,
)
# Try the next endpoint if the current one is not found
Expand Down
2 changes: 2 additions & 0 deletions charms/worker/k8s/tests/unit/test_k8sd_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def test_check_k8sd_not_found(self, mock_send_request):

with self.assertRaises(K8sdConnectionError):
self.api_manager.check_k8sd_ready()

mock_send_request.assert_has_calls(
[
call("/core/1.0/ready", "GET", EmptyResponse),
Expand All @@ -183,6 +184,7 @@ def test_check_k8sd_ready(self, mock_send_request):
mock_send_request.side_effect = [not_found, success]

self.api_manager.check_k8sd_ready()

mock_send_request.assert_has_calls(
[
call("/core/1.0/ready", "GET", EmptyResponse),
Expand Down

0 comments on commit 1cdcd56

Please sign in to comment.