diff --git a/cmd/metis/remote_cmd.go b/cmd/metis/remote_cmd.go index 2824157..1256972 100644 --- a/cmd/metis/remote_cmd.go +++ b/cmd/metis/remote_cmd.go @@ -380,7 +380,11 @@ func hasMountedChildren(children []struct { func humanHostPath(path string) string { path = strings.TrimSpace(path) if strings.HasPrefix(path, "/host-tmp/") { - return "/" + strings.TrimPrefix(path, "/host-tmp/") + trimmed := strings.TrimPrefix(path, "/host-tmp/") + if trimmed == "" { + return "/tmp" + } + return "/tmp/" + trimmed } if path == "/host-tmp" { return "/tmp" diff --git a/cmd/metis/remote_cmd_test.go b/cmd/metis/remote_cmd_test.go index 1c40d85..8bcee32 100644 --- a/cmd/metis/remote_cmd_test.go +++ b/cmd/metis/remote_cmd_test.go @@ -26,3 +26,9 @@ func TestOrasPushInvocationUsesRelativeWorkspacePaths(t *testing.T) { t.Fatalf("unexpected metadata arg: %q", args[3]) } } + +func TestHumanHostPathMapsMountedTmpBackToHostTmp(t *testing.T) { + if got := humanHostPath("/host-tmp/metis-flash-test"); got != "/tmp/metis-flash-test" { + t.Fatalf("expected /tmp/metis-flash-test, got %q", got) + } +} diff --git a/pkg/service/remote.go b/pkg/service/remote.go index 9da356b..087f26b 100644 --- a/pkg/service/remote.go +++ b/pkg/service/remote.go @@ -313,7 +313,7 @@ func (a *App) remoteDevicePodSpec(name, host, image string) map[string]any { "command": []string{ "metis", "remote-devices", "--max-device-bytes", fmt.Sprintf("%d", a.settings.MaxDeviceBytes), - "--host-tmp-dir", filepath.Join("/host-tmp", strings.TrimPrefix(a.settings.HostTmpDir, "/")), + "--host-tmp-dir", mountedHostTmpDir(a.settings.HostTmpDir), }, "securityContext": map[string]any{"privileged": true, "runAsUser": 0}, "volumeMounts": []map[string]any{ @@ -412,7 +412,7 @@ func (a *App) remoteFlashPodSpec(name, host, image, node, device, artifactRef st "--artifact-ref", artifactRef, "--work-dir", "/workspace/flash", "--harbor-registry", a.settings.HarborRegistry, - "--host-tmp-dir", filepath.Join("/host-tmp", strings.TrimPrefix(a.settings.HostTmpDir, "/")), + "--host-tmp-dir", mountedHostTmpDir(a.settings.HostTmpDir), }, "securityContext": map[string]any{"privileged": true, "runAsUser": 0}, "envFrom": []map[string]any{ @@ -453,3 +453,15 @@ func inventoryNodeArch(spec *inventory.NodeSpec, class *inventory.NodeClass) str } return "arm64" } + +func mountedHostTmpDir(path string) string { + path = strings.TrimSpace(path) + switch { + case path == "", path == "/tmp": + return "/host-tmp" + case strings.HasPrefix(path, "/tmp/"): + return filepath.Join("/host-tmp", strings.TrimPrefix(path, "/tmp/")) + default: + return filepath.Join("/host-tmp", strings.TrimPrefix(path, "/")) + } +} diff --git a/pkg/service/remote_test.go b/pkg/service/remote_test.go new file mode 100644 index 0000000..3c61b0f --- /dev/null +++ b/pkg/service/remote_test.go @@ -0,0 +1,12 @@ +package service + +import "testing" + +func TestMountedHostTmpDirMapsConfiguredTmpPathIntoMount(t *testing.T) { + if got := mountedHostTmpDir("/tmp/metis-flash-test"); got != "/host-tmp/metis-flash-test" { + t.Fatalf("expected /host-tmp/metis-flash-test, got %q", got) + } + if got := mountedHostTmpDir("/tmp"); got != "/host-tmp" { + t.Fatalf("expected /host-tmp, got %q", got) + } +}