Skip to content

Commit 46e040c

Browse files
author
Miguel Varela Ramos
authored
Add missing env vars to TaskAPI (#2144)
1 parent f0e3548 commit 46e040c

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

pkg/workloads/k8s.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,12 @@ func tensorFlowHandlerContainers(api *spec.API, envVars []kcore.EnvVar, isJob bo
657657
func taskEnvVars(api *spec.API) []kcore.EnvVar {
658658
envVars := apiContainerEnvVars(api)
659659
envVars = append(envVars,
660-
661660
kcore.EnvVar{
662661
Name: "CORTEX_TASK_SPEC",
663662
Value: TaskSpecPath,
664663
},
665664
)
665+
envVars = append(envVars, getKubexitEnvVars(APIContainerName)...)
666666
return envVars
667667
}
668668

test/e2e/e2e/tests.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,16 @@ def test_batch_api(
183183
job_spec = response.json()
184184

185185
# monitor job progress
186+
job_id = job_spec["job_id"]
187+
endpoint_override = (
188+
f"http://localhost:8888/batch/{api_name}?jobID={job_id}" if local_operator else None
189+
)
186190
assert job_done(
187191
client=client,
188-
api_name=job_spec["api_name"],
189-
job_id=job_spec["job_id"],
192+
api_name=api_name,
193+
job_id=job_id,
190194
timeout=job_timeout,
191-
local_operator=local_operator,
195+
endpoint_override=endpoint_override,
192196
), f"job did not succeed (api_name: {api_name}, job_id: {job_spec['job_id']})"
193197

194198
except:
@@ -330,6 +334,7 @@ def test_task_api(
330334
job_timeout: int = None,
331335
retry_attempts: int = 0,
332336
api_config_name: str = "cortex.yaml",
337+
local_operator: bool = False,
333338
):
334339
api_dir = TEST_APIS_DIR / api
335340
with open(str(api_dir / api_config_name)) as f:
@@ -341,28 +346,34 @@ def test_task_api(
341346
client.create_api(api_spec=api_specs[0], project_dir=str(api_dir))
342347

343348
try:
349+
endpoint_override = f"http://localhost:8888/tasks/{api_name}" if local_operator else None
344350
assert endpoint_ready(
345-
client=client, api_name=api_name, timeout=deploy_timeout
351+
client=client,
352+
api_name=api_name,
353+
timeout=deploy_timeout,
354+
endpoint_override=endpoint_override,
346355
), f"api {api_name} not ready"
347356

348357
response = None
349358
for _ in range(retry_attempts + 1):
350-
response = request_task(
351-
client,
352-
api_name,
353-
)
359+
response = request_task(client, api_name, local_operator=local_operator)
354360
if response.status_code == HTTPStatus.OK:
355361
break
356362

357363
time.sleep(1)
358364

359365
job_spec = response.json()
360366

367+
job_id = job_spec["job_id"]
368+
endpoint_override = (
369+
f"http://localhost:8888/tasks/{api_name}?jobID={job_id}" if local_operator else None
370+
)
361371
assert job_done(
362372
client=client,
363373
api_name=api_name,
364374
job_id=job_spec["job_id"],
365375
timeout=job_timeout,
376+
endpoint_override=endpoint_override,
366377
), f"task job did not succeed (api_name: {api_name}, job_id: {job_spec['job_id']})"
367378

368379
except:

test/e2e/e2e/utils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,15 @@ def _is_ready():
9696

9797

9898
def job_done(
99-
client: cx.Client, api_name: str, job_id: str, timeout: int = None, local_operator: bool = False
99+
client: cx.Client,
100+
api_name: str,
101+
job_id: str,
102+
timeout: int = None,
103+
endpoint_override: str = None,
100104
) -> bool:
101105
def _is_ready():
102-
if local_operator:
103-
job_info = requests.get(f"http://localhost:8888/batch/{api_name}?jobID={job_id}")
106+
if endpoint_override:
107+
job_info = requests.get(endpoint_override)
104108
job_info = job_info.json()
105109
return job_info["job_status"]["status"] == "succeeded"
106110

@@ -211,9 +215,13 @@ def request_task(
211215
api_name: str,
212216
config: Dict = None,
213217
timeout: int = None,
218+
local_operator: bool = False,
214219
):
215-
api_info = client.get_api(api_name)
216-
endpoint = api_info["endpoint"]
220+
if local_operator:
221+
endpoint = f"http://localhost:8888/tasks/{api_name}"
222+
else:
223+
api_info = client.get_api(api_name)
224+
endpoint = api_info["endpoint"]
217225

218226
payload = {}
219227
if config is not None:

test/e2e/tests/aws/test_task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ def test_task_api(printer: Callable, config: Dict, client: cx.Client, api: str):
3232
retry_attempts=5,
3333
deploy_timeout=config["global"]["task_deploy_timeout"],
3434
job_timeout=config["global"]["task_job_timeout"],
35+
local_operator=config["global"]["local_operator"],
3536
)

0 commit comments

Comments
 (0)