src.asqi.backends.kubernetes_backend¶
Kubernetes Job-based implementation of ContainerBackend.
Dispatches ASQI containers as Kubernetes Jobs using the K8s Jobs API. Images are assumed to be available in the cluster – no pull logic is performed.
Each Job runs the workload container alongside a native sidecar container
(K8s >= 1.28 initContainers entry with restartPolicy: Always) that
mediates S3 I/O via the shared emptyDir volume and a per-Job ConfigMap
carrying the workload’s InputRef / OutputDestination (AIP-2207).
- Required RBAC (see
asqi/k8s/rbac.yamlin the installed package): A ServiceAccount with
create / get / watch / deletepermissions onbatch/v1 Jobs,get / listoncore/v1 Pods, andcreate / deleteoncore/v1 ConfigMapsin the target namespace.- Optional dependency:
Install the Kubernetes Python client with:
pip install 'asqi-engineer[k8s]'- Unsupported Docker-semantics fields (fail-closed):
__volumes— the legacy Docker volume-passing key is rejected by_extract_io_refs(use__inputs/__outputwith AIP-2207InputRef/OutputDestination).
host_access— Docker socket / Docker-in-Docker access is not supported in K8s Jobs.
Attributes¶
Classes¶
Result of extracting AIP-2207 InputRef / OutputDestination from container args. |
|
ContainerBackend implementation that runs containers as Kubernetes Jobs. |
Module Contents¶
- src.asqi.backends.kubernetes_backend.logger¶
- class src.asqi.backends.kubernetes_backend.IORefs¶
Result of extracting AIP-2207 InputRef / OutputDestination from container args.
- Attributes:
- args:
argswith__inputs/__outputkeys stripped from any --test-params/--generation-paramsJSON payload. This is what the workload container actually receives — the workload sees local mount paths, never raw S3 refs.- inputs: Validated
InputReflist (possibly empty) destined for the sidecar’s
io.jsonConfigMap.- output: Validated
OutputDestination(single, optional) destined for the same ConfigMap.
- error: Non-
Nonewhen extraction fails (malformed refs, legacy __volumeskey, etc.). Callers MUST fail-closed and skip Job creation whenerroris set — no silent strip.
- args:
- args: list[str]¶
- inputs: list[asqi.schemas.InputRef]¶
- output: asqi.schemas.OutputDestination | None = None¶
- error: str | None = None¶
- class src.asqi.backends.kubernetes_backend.KubernetesBackend(namespace: str = _DEFAULT_NAMESPACE, *, sidecar_image: str | None = None, sidecar_sa_name: str | None = None, sidecar_configmap_name: str | None = None, sidecar_secret_name: str | None = None)¶
ContainerBackend implementation that runs containers as Kubernetes Jobs.
Each call to
run()creates a K8s Job, waits for it to complete, collects its logs, then deletes the Job. Images are assumed to be available in the cluster — no pull logic is performed.- Args:
- namespace: Kubernetes namespace in which Jobs are created.
Defaults to
"default".
- RBAC requirement:
The ServiceAccount must have
create / get / watch / deletepermissions onbatch/v1 Jobsandget / listoncore/v1 Podsin namespace. Seeasqi/k8s/rbac.yamlin the installed package for a ready-to-apply manifest.
- run(image: str, args: list[str], container_config: asqi.config.ContainerConfig, environment: dict[str, str] | None = None, name: str | None = None, workflow_id: str = '', manifest: asqi.schemas.Manifest | None = None) dict[str, Any]¶
Create a K8s Job for image, wait for completion, and return results.
- Args:
image: Container image reference. args: Command-line arguments passed to the container. May contain
__inputs/__outputkeys inside--test-params/--generation-paramsJSON payloads; these are extracted into the per-Job ConfigMap and stripped before reaching the workload (see_extract_io_refs()).container_config: Execution configuration (timeout, resource limits, etc.). environment: Optional environment variables injected into the workload container. name: Optional human-readable hint used to build the Job name. workflow_id: Workflow identifier attached as a Job label and as
the sidecar’s
AIP_JOB_HANDLEenv var.- manifest: Optional manifest for the container image.
host_access=True causes an immediate fail-closed return without creating a Job.
- manifest: Optional manifest for the container image.
- Returns:
Dict with
success,exit_code,output,error,container_id.
- shutdown(workflow_ids: list[str] | None = None) None¶
Delete all ASQI K8s Jobs, optionally scoped to specific workflow IDs.
- Args:
- workflow_ids: If
None, deletes all Jobs labelled service=asqi_engineerin the namespace. Otherwise only Jobs matching the given workflow IDs are deleted.
- workflow_ids: If
- check_images(images: list[str]) dict[str, bool]¶
Return
Truefor every image – K8s does not support pre-flight image checks.Image availability is determined at pod scheduling time by the kubelet.
- pull_images(images: list[str]) None¶
No-op: image pulling is handled by the kubelet (
imagePullPolicy).Images are assumed to be available in the cluster registry.
- extract_manifest(image: str, manifest_path: str = ContainerConfig.MANIFEST_PATH) asqi.schemas.Manifest | None¶
Extract
manifest.yamlfrom an image by running a one-shot K8s Job.The Job runs
cat <manifest_path>; the pod stdout is parsed as YAML.- Args:
image: Container image reference. manifest_path: Path to the manifest file inside the container.
- Returns:
Parsed
ManifestorNone.- Raises:
ManifestExtractionError: If the Job fails or the YAML cannot be parsed.