fix: use runtime namespace for session PVCs

This commit is contained in:
lyon
2026-06-20 10:53:24 +08:00
parent 9e1f5ac812
commit 7c51f5b9f0
2 changed files with 26 additions and 4 deletions
+15 -3
View File
@@ -36,6 +36,7 @@ export interface SessionPvcOptions {
const defaultStorageClassName = "local-path";
const defaultPvcSize = "1Gi";
const defaultSubdir = "sessions";
const defaultNamespace = "agentrun-v01";
export function sessionPvcNameFor(sessionId: string): string {
const sanitized = sanitizeSessionIdForPvc(sessionId);
@@ -45,8 +46,19 @@ export function sessionPvcNameFor(sessionId: string): string {
export function sanitizeSessionIdForPvc(sessionId: string): string {
return sessionId.toLowerCase().replace(/[^a-z0-9-]+/gu, "-").replace(/^-+|-+$/gu, "");
}
function runtimeNamespace(): string {
const value = process.env.AGENTRUN_RUNTIME_NAMESPACE?.trim();
return value && value.length > 0 ? value : defaultNamespace;
}
function runtimeLane(): string {
const value = process.env.AGENTRUN_LANE?.trim();
return value && value.length > 0 ? value : "v0.1";
}
export function buildSessionPvcSpec(input: { sessionId: string; namespace?: string; options: SessionPvcOptions }): SessionPvcSpec {
const namespace = input.namespace ?? "agentrun-v01";
const namespace = input.namespace ?? runtimeNamespace();
return {
pvcName: sessionPvcNameFor(input.sessionId),
namespace,
@@ -84,7 +96,7 @@ export async function createSessionPvc(input: { store: AgentRunStore; sessionId:
const manifest: JsonRecord = {
apiVersion: "v1",
kind: "PersistentVolumeClaim",
metadata: { name: spec.pvcName, namespace: spec.namespace, labels: { "agentrun.pikastech.local/session-id": input.sessionId, "agentrun.pikastech.local/lane": "v0.1" } },
metadata: { name: spec.pvcName, namespace: spec.namespace, labels: { "agentrun.pikastech.local/session-id": input.sessionId, "agentrun.pikastech.local/lane": runtimeLane() } },
spec: { accessModes: ["ReadWriteOnce"], storageClassName: spec.storageClassName, resources: { requests: { storage: spec.size } } },
};
const handler = resolveHandler(input.options);
@@ -221,7 +233,7 @@ export async function runSessionStorageGc(input: { store: AgentRunStore; options
if (session.activeRunId || session.activeCommandId) { skipped++; continue; }
if (session.storageKind !== "pvc" || !session.storagePvcName) { skipped++; continue; }
try {
await handler({ args: ["delete", "pvc", session.storagePvcName, "-n", session.storageNamespace ?? "agentrun-v01", "--ignore-not-found"] });
await handler({ args: ["delete", "pvc", session.storagePvcName, "-n", session.storageNamespace ?? runtimeNamespace(), "--ignore-not-found"] });
await input.store.markSessionStorageEvicted({ sessionId: session.sessionId, pvcName: session.storagePvcName });
deleted++;
deletedPvcNames.push(session.storagePvcName);