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

  1. parses __volumes from the --test-params / --generation-params JSON payloads,

  2. uploads __volumes["input"] to a workflow/item-scoped S3 prefix,

  3. emits InputRef per uploaded file and a single OutputDestination for the output prefix,

  4. rewrites the payload: adds __inputs / __output (consumed by asqi.backends.kubernetes_backend._extract_io_refs()), strips __volumes (legacy Docker key — AIP-2473 rejects it fail-closed), and rewrites the plain volumes key 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

Functions

s3_config_from_env(...)

Build an S3ClientConfig + bucket + key-prefix from env vars.

stage_k8s_io(→ StagingResult)

Stage K8s inputs/outputs by rewriting command_args in place.

fetch_k8s_outputs(→ list[str])

Mirror staging.output_prefix from S3 back to staging.local_output_path.

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 None if the

workload did not declare a __volumes["output"].

output_prefix: Key prefix under output_bucket reserved for the

sidecar to publish workload outputs.

local_output_path: Original host-side path from __volumes["output"].

fetch_k8s_outputs() mirrors output_prefix back 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) where key_prefix may 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_args in place.

Walks command_args for --test-params / --generation-params JSON payloads. For each payload that carries __volumes:

  • If __volumes["input"] points at an existing directory, every file under it is uploaded to s3://<bucket>/<key_prefix>/<workflow_id>/<item_id>/input/, one InputRef is emitted per file. A single non-directory file is also supported.

  • If __volumes["output"] is set, a single OutputDestination is emitted pointing at s3://<bucket>/<key_prefix>/<workflow_id>/<item_id>/output/. The sidecar publishes the workload’s /output back to that prefix.

  • __inputs and __output are added to the payload; __volumes is stripped (AIP-2473 rejects it fail-closed); the plain volumes key is rewritten to the AIP-2473 mount paths.

A workload without __volumes is left unchanged (the JSON arg is not even re-serialised). Args that aren’t JSON are also skipped — the contract matches asqi.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 via StagingResult.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_bucket then create_bucket if

missing. Leave False in production where the bucket is provisioned by Helm/Terraform.

region: Required when ensure_bucket=True to set the

LocationConstraint.

Returns:

A StagingResult whose command_args should be passed to the K8s backend in place of the original list. If no __volumes is present anywhere, the result still contains a copy of the original args; output_bucket and local_output_path will be None (and fetch_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_prefix from S3 back to staging.local_output_path.

No-op when staging did not declare an output destination (e.g. workload without __volumes["output"]). Returns the list of relative paths written (for logging / diagnostics).