Skip to content

Commit 3dd2f8c

Browse files
authored
Merge branch 'main' into k8s-autoscaling
2 parents 393a3ec + 361ceac commit 3dd2f8c

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/lib/onboard/sandbox-gpu-preflight-routing.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,61 @@ describe("sandbox GPU preflight routing", () => {
9292
expect(dockerInfo).not.toHaveBeenCalled();
9393
});
9494

95+
it("falls back to Docker's default CDI spec dirs when docker info reports none (#7330)", () => {
96+
const getDockerCdiSpecDirs = vi.fn(() => []);
97+
const findReadableNvidiaCdiSpecFiles = (dirs: string[]) =>
98+
dirs.length === 2 && dirs[0] === "/etc/cdi" && dirs[1] === "/var/run/cdi"
99+
? ["/etc/cdi/nvidia.yaml"]
100+
: [];
101+
const exitProcess = (code: number): never => {
102+
throw new Error(`exit:${code}`);
103+
};
104+
105+
expect(() =>
106+
validateSandboxGpuPreflight(
107+
sandboxGpuConfig(),
108+
{
109+
platform: "linux",
110+
env: {},
111+
release: "6.8.0-generic",
112+
procVersion: "Linux version 6.8.0-generic",
113+
dockerInfoFormat: vi.fn(),
114+
getDockerCdiSpecDirs,
115+
findReadableNvidiaCdiSpecFiles,
116+
},
117+
exitProcess,
118+
),
119+
).not.toThrow();
120+
});
121+
122+
it("still fails when the fallback CDI spec dirs hold no NVIDIA spec (#7330)", () => {
123+
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
124+
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((
125+
code?: number | string | null,
126+
) => {
127+
throw new Error(`exit:${code}`);
128+
}) as never);
129+
130+
try {
131+
expect(() =>
132+
validateSandboxGpuPreflight(sandboxGpuConfig(), {
133+
platform: "linux",
134+
env: {},
135+
release: "6.8.0-generic",
136+
procVersion: "Linux version 6.8.0-generic",
137+
dockerInfoFormat: vi.fn(),
138+
getDockerCdiSpecDirs: vi.fn(() => []),
139+
findReadableNvidiaCdiSpecFiles: vi.fn(() => []),
140+
}),
141+
).toThrow("exit:1");
142+
const message = errorSpy.mock.calls.map((call) => call[0]).join("\n");
143+
expect(message).toContain("Docker CDI GPU support was not detected");
144+
} finally {
145+
errorSpy.mockRestore();
146+
exitSpy.mockRestore();
147+
}
148+
});
149+
95150
it("skips CDI spec validation on Docker Desktop WSL so Docker --gpus can be used", () => {
96151
const logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined);
97152
const getDockerCdiSpecDirs = vi.fn(() => ["/etc/cdi"]);

src/lib/onboard/sandbox-gpu-preflight.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ export { formatSandboxGpuPassthroughNote } from "./sandbox-gpu-notes";
1818

1919
const SANDBOX_GPU_PREFLIGHT_TIMEOUT_MS = 30_000;
2020

21+
// Docker Engine's built-in CDI spec directories. `docker info` can report no
22+
// CDISpecDirs (daemon unreachable from this process, or an engine that omits
23+
// the field) even though CDI works, so the preflight falls back to these
24+
// before declaring CDI unsupported (#7330).
25+
const FALLBACK_DOCKER_CDI_SPEC_DIRS = ["/etc/cdi", "/var/run/cdi"];
26+
2127
export type SandboxGpuPreflightDeps = WslDockerDesktopDetectionDeps & {
2228
getDockerCdiSpecDirs?: () => string[];
2329
findReadableNvidiaCdiSpecFiles?: (dirs: string[]) => string[];
@@ -368,7 +374,9 @@ export function validateSandboxGpuPreflight(
368374
return;
369375
}
370376

371-
const cdiSpecDirs = (deps.getDockerCdiSpecDirs ?? getDockerCdiSpecDirs)();
377+
const reportedCdiSpecDirs = (deps.getDockerCdiSpecDirs ?? getDockerCdiSpecDirs)();
378+
const cdiSpecDirs =
379+
reportedCdiSpecDirs.length > 0 ? reportedCdiSpecDirs : FALLBACK_DOCKER_CDI_SPEC_DIRS;
372380
const cdiSpecFiles = (deps.findReadableNvidiaCdiSpecFiles ?? findReadableNvidiaCdiSpecFiles)(
373381
cdiSpecDirs,
374382
);

0 commit comments

Comments
 (0)