cri-client: normalize unix socket endpoints in target helper

This commit is contained in:
Davanum Srinivas
2026-03-23 06:41:34 +01:00
parent 8298942a3a
commit 022a649b11
2 changed files with 11 additions and 0 deletions

View File

@@ -19,6 +19,12 @@ package cri
import "strings"
func clientTargetForAddress(addr string) string {
// Defensive: normalize callers that pass a unix endpoint instead of the
// parsed socket path.
if strings.HasPrefix(addr, "unix:///") {
addr = strings.TrimPrefix(addr, "unix://")
}
// grpc defaults to the DNS resolver for bare targets. Use the passthrough
// resolver for socket-style addresses so the custom dialer gets the raw path.
if strings.HasPrefix(addr, "/") {

View File

@@ -29,6 +29,11 @@ func TestClientTargetForAddress(t *testing.T) {
addr: "/run/containerd/containerd.sock",
want: "passthrough:////run/containerd/containerd.sock",
},
{
name: "unix socket endpoint",
addr: "unix:///run/containerd/containerd.sock",
want: "passthrough:////run/containerd/containerd.sock",
},
{
name: "windows pipe path",
addr: "//./pipe/containerd-containerd",