Skip to content

Commit

Permalink
Fix sync Service.ready_pods() (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson authored Feb 29, 2024
1 parent 34cdf23 commit 8c8fab9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kr8s/_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ async def _ready_pods(self) -> List[Pod]:
label_selector=dict_to_selector(self.spec["selector"]),
namespace=self.namespace,
)
return [pod for pod in pods if await pod.ready()]
return [pod for pod in pods if await pod._ready()]

async def ready(self) -> bool:
"""Check if the service is ready."""
Expand Down
18 changes: 18 additions & 0 deletions kr8s/tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from kr8s.asyncio.portforward import PortForward
from kr8s.objects import Pod as SyncPod
from kr8s.objects import Service as SyncService
from kr8s.objects import get_class, new_class, object_from_spec
from kr8s.objects import objects_from_files as sync_objects_from_files

Expand Down Expand Up @@ -568,6 +569,23 @@ async def test_pod_port_forward_context_manager(nginx_service):
resp.read()


def test_pod_port_forward_context_manager_sync(nginx_service):
async_nginx_service = nginx_service
nginx_service = SyncService.get(
async_nginx_service.name, namespace=async_nginx_service.namespace
)
[nginx_pod, *_] = nginx_service.ready_pods()
with nginx_pod.portforward(80) as port:
with httpx.Client(timeout=DEFAULT_TIMEOUT) as session:
resp = session.get(f"http://localhost:{port}/")
assert resp.status_code == 200
resp = session.get(f"http://localhost:{port}/foo")
assert resp.status_code == 404
resp = session.get(f"http://localhost:{port}/foo.dat")
assert resp.status_code == 200
resp.read()


@pytest.mark.skip(reason="For manual testing only")
async def test_pod_port_forward_context_manager_manual(nginx_service):
[nginx_pod, *_] = await nginx_service.ready_pods()
Expand Down

0 comments on commit 8c8fab9

Please sign in to comment.