src.asqi.storage.k8s_io_staging¶
S3 staging for the K8s execution path.
When RUN_BACKEND=k8s, asqi-engineer uploads the workload’s local input
files to S3 before the KubernetesBackend
sees the args. The backend’s per-Job ConfigMap then carries
InputRef / OutputDestination
that the sidecar (AIP-2208) consumes to materialise /shared/input and
publish /shared/output back to S3.
This module is the wedge between
asqi.workflow._execute_container_job() and the K8s backend. It
parses
__volumesfrom the--test-params/--generation-paramsJSON payloads,uploads
__volumes["input"]to a workflow/item-scoped S3 prefix,emits
InputRefper uploaded file and a singleOutputDestinationfor the output prefix,rewrites the payload: adds
__inputs/__output(consumed byasqi.backends.kubernetes_backend._extract_io_refs()), strips__volumes(legacy Docker key — AIP-2473 rejects it fail-closed), and rewrites the plainvolumeskey so the workload sees{"input": "/input", "output": "/output"}(the AIP-2473 hardcoded sidecar mount points).
Docker remains unchanged: this module is only invoked when the caller already knows it’s on the K8s path.
Attributes¶
Classes¶
Outcome of |
Functions¶
|
Build an |
|
Stage K8s inputs/outputs by rewriting |
|
Mirror |
Module Contents¶
- src.asqi.storage.k8s_io_staging.logger¶
- class src.asqi.storage.k8s_io_staging.StagingResult¶
Outcome of
stage_k8s_io().- Attributes:
- command_args: Modified args list (caller passes this to the backend
instead of the original
command_args).- output_bucket: Bucket holding workload output, or
Noneif the workload did not declare a
__volumes["output"].- output_prefix: Key prefix under
output_bucketreserved for the sidecar to publish workload outputs.
- local_output_path: Original host-side path from
__volumes["output"]. fetch_k8s_outputs()mirrorsoutput_prefixback to here after the Job completes so downstream code (e.g._translate_container_output_paths()) sees results at the same place Docker leaves them.
input_keys: S3 keys uploaded for inputs (for diagnostics / cleanup).
- command_args: list[str]¶
- output_bucket: str | None = None¶
- output_prefix: str | None = None¶
- local_output_path: str | None = None¶
- input_keys: list[str] = []¶
- src.asqi.storage.k8s_io_staging.s3_config_from_env() tuple[asqi.storage.s3.S3ClientConfig, str, str]¶
Build an
S3ClientConfig+ bucket + key-prefix from env vars.Reads the existing
AIP_ASQI_RUNNER_S3_*env vars (since asqi-engineer workflow steps execute in-process inside the asqi-runner Pod, the same env is available).- Returns:
A 3-tuple
(config, bucket, key_prefix)wherekey_prefixmay be empty.- Raises:
RuntimeError: If a required env var is missing.
- src.asqi.storage.k8s_io_staging.stage_k8s_io(*, workflow_id: str, item_id: str, command_args: list[str], s3_client: Any, bucket: str, key_prefix: str = '', ensure_bucket: bool = False, region: str = '') StagingResult¶
Stage K8s inputs/outputs by rewriting
command_argsin place.Walks
command_argsfor--test-params/--generation-paramsJSON payloads. For each payload that carries__volumes:If
__volumes["input"]points at an existing directory, every file under it is uploaded tos3://<bucket>/<key_prefix>/<workflow_id>/<item_id>/input/, oneInputRefis emitted per file. A single non-directory file is also supported.If
__volumes["output"]is set, a singleOutputDestinationis emitted pointing ats3://<bucket>/<key_prefix>/<workflow_id>/<item_id>/output/. The sidecar publishes the workload’s/outputback to that prefix.__inputsand__outputare added to the payload;__volumesis stripped (AIP-2473 rejects it fail-closed); the plainvolumeskey is rewritten to the AIP-2473 mount paths.
A workload without
__volumesis left unchanged (the JSON arg is not even re-serialised). Args that aren’t JSON are also skipped — the contract matchesasqi.backends.kubernetes_backend._extract_io_refs().- Args:
workflow_id: DBOS workflow id; used to scope the S3 prefix. item_id: Test or generation-job id; used to scope the S3 prefix. command_args: The args list as built by
create_test_execution_plan/
create_data_generation_plan. Not mutated; a new list is returned viaStagingResult.command_args.s3_client: A boto3 S3 client (from
asqi.storage.s3.make_s3_client()). bucket: Bucket to upload to / read from. key_prefix: Optional global S3 prefix beneath which the<workflow_id>/<item_id>/scope is created.- ensure_bucket: If
True,head_bucketthencreate_bucketif missing. Leave
Falsein production where the bucket is provisioned by Helm/Terraform.- region: Required when
ensure_bucket=Trueto set the LocationConstraint.
- ensure_bucket: If
- Returns:
A
StagingResultwhosecommand_argsshould be passed to the K8s backend in place of the original list. If no__volumesis present anywhere, the result still contains a copy of the original args;output_bucketandlocal_output_pathwill beNone(andfetch_k8s_outputs()becomes a no-op).
- src.asqi.storage.k8s_io_staging.fetch_k8s_outputs(staging: StagingResult, s3_client: Any) list[str]¶
Mirror
staging.output_prefixfrom S3 back tostaging.local_output_path.No-op when
stagingdid not declare an output destination (e.g. workload without__volumes["output"]). Returns the list of relative paths written (for logging / diagnostics).