Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass extra arguments to gateway runtime with container pod #5631

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions jina/orchestrate/pods/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import asyncio
import copy
import multiprocessing
import threading
import os
import re
import signal
import threading
import time
from typing import TYPE_CHECKING, Dict, Optional, Union

Expand All @@ -21,6 +21,7 @@
get_docker_network,
get_gpu_device_requests,
)
from jina.parsers import set_gateway_parser
from jina.serve.runtimes.asyncio import AsyncNewLoopRuntime
from jina.serve.runtimes.gateway import GatewayRuntime

Expand Down Expand Up @@ -74,9 +75,15 @@ def _docker_run(

args.native = True

parser = (
set_gateway_parser()
if args.pod_role == PodRoleType.GATEWAY
else set_pod_parser()
)

non_defaults = ArgNamespace.get_non_defaults_args(
args,
set_pod_parser(),
parser,
taboo={
'uses',
'entrypoint',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def _get_response():
'arg3': self.arg3,
}

@app.get(path='/runtime_info')
def _get_info():
return {
'ports': self.ports,
'protocols': self.protocols,
}

@app.get(
path='/stream',
response_model=ProcessedResponseModel,
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/orchestrate/pods/container/test_container_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import time

import pytest
import requests

from jina import Flow
from jina.constants import __cache_path__
from jina.enums import GatewayProtocolType
from jina.excepts import RuntimeFailToStart
from jina.helper import random_port
from jina.orchestrate.pods.container import ContainerPod
Expand Down Expand Up @@ -273,6 +275,11 @@ def test_container_pod_custom_gateway(dummy_custom_gateway_docker_image_built):
port, {'arg1': 'hello', 'arg2': 'world', 'arg3': 'default-arg3'}
)

# validate protocol inside the gateway
resp = requests.get(f'http://127.0.0.1:{port}/runtime_info').json()
assert resp['protocols'] == [GatewayProtocolType.HTTP]
assert resp['ports'] == [int(port)]

time.sleep(
2
) # to avoid desync between the start and close process which could lead to container never get terminated
Expand Down