Skip to content

Commit d578c02

Browse files
authored
Merge pull request #204 from craddm/api/add-logs
Add a function to the API for retrieving logs
2 parents 26102e5 + a2891cb commit d578c02

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

fridge-job-api/app/main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,42 @@ async def get_workflows(
237237
return extract_argo_workflows(r.json())
238238

239239

240+
@app.get("/workflows/{namespace}/{workflow_name}/log", tags=["Argo Workflows"])
241+
async def get_workflow_log(
242+
namespace: str,
243+
workflow_name: str,
244+
pod_name: str | None = None,
245+
container_name: str = "main",
246+
verified: Annotated[bool, "Verify the request with basic auth"] = Depends(
247+
verify_request
248+
),
249+
):
250+
params = {
251+
"podName": pod_name or workflow_name,
252+
"logOptions.container": container_name,
253+
}
254+
255+
r = requests.get(
256+
f"{ARGO_SERVER}/api/v1/workflows/{namespace}/{workflow_name}/log",
257+
verify=VERIFY_TLS,
258+
headers={"Authorization": f"Bearer {argo_token()}"},
259+
params=params,
260+
stream=True,
261+
)
262+
if r.status_code != 200:
263+
raise HTTPException(
264+
status_code=r.status_code, detail=parse_argo_error(r.json())
265+
)
266+
267+
lines = []
268+
for line in r.iter_lines():
269+
if line:
270+
parsed = json.loads(line)
271+
if "result" in parsed:
272+
lines.append(parsed["result"].get("content", ""))
273+
return {"podName": workflow_name, "log": "\n".join(lines)}
274+
275+
240276
@app.get("/workflows/{namespace}/{workflow_name}", tags=["Argo Workflows"])
241277
async def get_single_workflow(
242278
namespace: Annotated[str, "The namespace to list workflows from"],

infra/fridge/isolated-cluster/components/api_server.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ def __init__(
109109
"update",
110110
],
111111
),
112+
PolicyRuleArgs(
113+
api_groups=[""],
114+
resources=[
115+
"pods",
116+
"pods/log",
117+
],
118+
verbs=[
119+
"get",
120+
"list",
121+
"watch",
122+
],
123+
),
112124
],
113125
opts=child_opts,
114126
)
@@ -122,7 +134,7 @@ def __init__(
122134
opts=child_opts,
123135
)
124136

125-
CustomResource(
137+
self.minio_policy = CustomResource(
126138
resource_name="minio-policy-readwrite",
127139
api_version="sts.min.io/v1alpha1",
128140
kind="PolicyBinding",

0 commit comments

Comments
 (0)