fix: verify PVC exists after creation in ensureAgentDbPvc
Before creating a PVC, ensureAgentDbPvc checks if it exists and creates it if not. However, the Kubernetes API may return a Success response without actually creating the resource. This commit adds a verification step after createPvc to confirm the PVC actually exists before returning. Fixes FAR-84. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
Binary file not shown.
Binary file not shown.
@@ -897,6 +897,11 @@ export async function ensureAgentDbPvc(
|
|||||||
},
|
},
|
||||||
}, kubeconfigPath);
|
}, kubeconfigPath);
|
||||||
|
|
||||||
|
const verified = await getPvc(namespace, pvcName, kubeconfigPath);
|
||||||
|
if (!verified) {
|
||||||
|
throw new Error(`PVC ${pvcName} was not created in namespace ${namespace}`);
|
||||||
|
}
|
||||||
|
|
||||||
return pvcName;
|
return pvcName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,9 @@ describe("ensureAgentDbPvc", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("creates PVC when it does not exist and returns the name", async () => {
|
it("creates PVC when it does not exist and returns the name", async () => {
|
||||||
vi.mocked(getPvc).mockResolvedValue(null);
|
vi.mocked(getPvc)
|
||||||
|
.mockResolvedValueOnce(null)
|
||||||
|
.mockResolvedValueOnce({ metadata: { name: `opencode-db-${AGENT_ID}` } } as never);
|
||||||
vi.mocked(createPvc).mockResolvedValue({} as never);
|
vi.mocked(createPvc).mockResolvedValue({} as never);
|
||||||
const result = await ensureAgentDbPvc(AGENT_ID, NAMESPACE, {
|
const result = await ensureAgentDbPvc(AGENT_ID, NAMESPACE, {
|
||||||
agentDbMode: "dedicated_pvc",
|
agentDbMode: "dedicated_pvc",
|
||||||
@@ -62,7 +64,9 @@ describe("ensureAgentDbPvc", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("defaults storage capacity to 1Gi when agentDbStorageCapacity is not set", async () => {
|
it("defaults storage capacity to 1Gi when agentDbStorageCapacity is not set", async () => {
|
||||||
vi.mocked(getPvc).mockResolvedValue(null);
|
vi.mocked(getPvc)
|
||||||
|
.mockResolvedValueOnce(null)
|
||||||
|
.mockResolvedValueOnce({ metadata: { name: `opencode-db-${AGENT_ID}` } } as never);
|
||||||
vi.mocked(createPvc).mockResolvedValue({} as never);
|
vi.mocked(createPvc).mockResolvedValue({} as never);
|
||||||
await ensureAgentDbPvc(AGENT_ID, NAMESPACE, {
|
await ensureAgentDbPvc(AGENT_ID, NAMESPACE, {
|
||||||
agentDbMode: "dedicated_pvc",
|
agentDbMode: "dedicated_pvc",
|
||||||
@@ -81,7 +85,9 @@ describe("ensureAgentDbPvc", () => {
|
|||||||
|
|
||||||
it("sanitizes agent ID in PVC name (strips non-alphanumeric except hyphens)", async () => {
|
it("sanitizes agent ID in PVC name (strips non-alphanumeric except hyphens)", async () => {
|
||||||
const weirdId = "Agent/ID:with@special!chars";
|
const weirdId = "Agent/ID:with@special!chars";
|
||||||
vi.mocked(getPvc).mockResolvedValue(null);
|
vi.mocked(getPvc)
|
||||||
|
.mockResolvedValueOnce(null)
|
||||||
|
.mockResolvedValueOnce({ metadata: { name: "opencode-db-agentidwithspecialchars" } } as never);
|
||||||
vi.mocked(createPvc).mockResolvedValue({} as never);
|
vi.mocked(createPvc).mockResolvedValue({} as never);
|
||||||
const result = await ensureAgentDbPvc(weirdId, NAMESPACE, {
|
const result = await ensureAgentDbPvc(weirdId, NAMESPACE, {
|
||||||
agentDbMode: "dedicated_pvc",
|
agentDbMode: "dedicated_pvc",
|
||||||
|
|||||||
Reference in New Issue
Block a user