feat(v0.1): runner Job 直接挂载 per-session PVC + env 透传
PR C 起步:k8s-job.ts 加 sessionPvc volume + env passthrough - src/runner/k8s-job.ts: 新 RunnerSessionPvcOptions 接口;manifest 多渲染 agentrun-sessions volume + volumeMount;env 多透传 AGENTRUN_SESSION_PVC_NAME / _NAMESPACE / _MOUNT_PATH / AGENTRUN_CODEX_ROLLOUT_SUBDIR - src/mgr/kubernetes-runner-job.ts: run 引用 session 时查 session storage kind=pvc 自动构造 sessionPvc 透传给 manifest 渲染;kind=evicted 已在 PR B 短路返回 session-store-evicted - selftest: 1 新 case runner-k8s-job-session-pvc-volume-and-env 验证 PVC volume + env 全套透传 后续 PR C 剩余:src/backend/codex-stdio.ts emit codex-rollout-storage-mounted 事件 + session-store-evicted 升级;3 个 codex-stdio 端到端 case。
This commit is contained in:
+23
-3
@@ -19,9 +19,17 @@ export interface RunnerJobRenderOptions {
|
||||
backoffLimit?: number;
|
||||
ttlSecondsAfterFinished?: number;
|
||||
transientEnv?: RunnerTransientEnv[];
|
||||
sessionPvc?: RunnerSessionPvcOptions;
|
||||
dryRun?: boolean;
|
||||
}
|
||||
|
||||
export interface RunnerSessionPvcOptions {
|
||||
pvcName: string;
|
||||
namespace: string;
|
||||
mountPath: string;
|
||||
codexRolloutSubdir: string;
|
||||
}
|
||||
|
||||
export interface RunnerTransientEnv {
|
||||
name: string;
|
||||
value: string;
|
||||
@@ -91,9 +99,10 @@ export function renderRunnerJobManifest(options: RunnerJobRenderOptions): { mani
|
||||
const jobName = `agentrun-v01-runner-${shortDnsHash(options.run.id, attemptId)}`;
|
||||
const secretRefs = credentialProjections(options.run, namespace);
|
||||
const toolCredentials = toolCredentialProjections(options.run, namespace);
|
||||
const sessionPvc = options.sessionPvc;
|
||||
const warnings: string[] = [];
|
||||
if (secretRefs.length === 0) warnings.push("run executionPolicy.secretScope 未声明 provider SecretRef;runner 将按 secret-unavailable 上报,而不会降级直连外部凭据");
|
||||
const env = runnerEnv(options, { namespace, jobName, runnerId, attemptId, sourceCommit, secretRefs, toolCredentials });
|
||||
const env = runnerEnv(options, { namespace, jobName, runnerId, attemptId, sourceCommit, secretRefs, toolCredentials, sessionPvc });
|
||||
const manifest: JsonRecord = {
|
||||
apiVersion: "batch/v1",
|
||||
kind: "Job",
|
||||
@@ -132,6 +141,7 @@ export function renderRunnerJobManifest(options: RunnerJobRenderOptions): { mani
|
||||
volumeMounts: [
|
||||
{ name: "runner-home", mountPath: "/home/agentrun" },
|
||||
...secretRefs.map((item) => ({ name: item.volumeName, mountPath: item.projectionMountPath, readOnly: true })),
|
||||
...(sessionPvc ? [{ name: "agentrun-sessions", mountPath: sessionPvc.mountPath, readOnly: false }] : []),
|
||||
],
|
||||
resources: {
|
||||
requests: { cpu: "250m", memory: "512Mi" },
|
||||
@@ -144,7 +154,11 @@ export function renderRunnerJobManifest(options: RunnerJobRenderOptions): { mani
|
||||
},
|
||||
},
|
||||
],
|
||||
volumes: [{ name: "runner-home", emptyDir: {} }, ...secretRefs.map(secretVolume)],
|
||||
volumes: [
|
||||
{ name: "runner-home", emptyDir: {} },
|
||||
...secretRefs.map(secretVolume),
|
||||
...(sessionPvc ? [{ name: "agentrun-sessions", persistentVolumeClaim: { claimName: sessionPvc.pvcName } }] : []),
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -152,7 +166,7 @@ export function renderRunnerJobManifest(options: RunnerJobRenderOptions): { mani
|
||||
return { manifest, namespace, jobName, runnerId, attemptId, sourceCommit, serviceAccountName, secretRefs, toolCredentials, warnings, ttlSecondsAfterFinished };
|
||||
}
|
||||
|
||||
function runnerEnv(options: RunnerJobRenderOptions, context: { namespace: string; jobName: string; runnerId: string; attemptId: string; sourceCommit: string; secretRefs: CredentialProjection[]; toolCredentials: ToolCredentialProjection[] }): JsonRecord[] {
|
||||
function runnerEnv(options: RunnerJobRenderOptions, context: { namespace: string; jobName: string; runnerId: string; attemptId: string; sourceCommit: string; secretRefs: CredentialProjection[]; toolCredentials: ToolCredentialProjection[]; sessionPvc: RunnerSessionPvcOptions | undefined }): JsonRecord[] {
|
||||
const selectedSecret = context.secretRefs.find((item) => item.profile === options.run.backendProfile);
|
||||
const codexHome = selectedSecret?.runtimeMountPath ?? defaultRuntimeHome(options.run.backendProfile);
|
||||
return [
|
||||
@@ -180,6 +194,12 @@ function runnerEnv(options: RunnerJobRenderOptions, context: { namespace: string
|
||||
{ name: "HOME", value: "/home/agentrun" },
|
||||
{ name: "CODEX_HOME", value: codexHome },
|
||||
...(selectedSecret ? [{ name: "AGENTRUN_CODEX_SECRET_HOME", value: selectedSecret.projectionMountPath }] : []),
|
||||
...(context.sessionPvc ? [
|
||||
{ name: "AGENTRUN_SESSION_PVC_NAME", value: context.sessionPvc.pvcName },
|
||||
{ name: "AGENTRUN_SESSION_PVC_NAMESPACE", value: context.sessionPvc.namespace },
|
||||
{ name: "AGENTRUN_SESSION_PVC_MOUNT_PATH", value: context.sessionPvc.mountPath },
|
||||
{ name: "AGENTRUN_CODEX_ROLLOUT_SUBDIR", value: context.sessionPvc.codexRolloutSubdir },
|
||||
] : []),
|
||||
...toolCredentialEnvVars(context.toolCredentials),
|
||||
...transientEnvVars(options.transientEnv ?? []),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user