diff --git a/internal/docker/client.go b/internal/docker/client.go index a1ac7612..eaaefe9d 100644 --- a/internal/docker/client.go +++ b/internal/docker/client.go @@ -6,6 +6,7 @@ import ( "maps" "net" "net/http" + "net/url" "reflect" "sync" "sync/atomic" @@ -169,9 +170,26 @@ func NewClient(cfg types.DockerProviderConfig, unique ...bool) (*SharedClient, e client.WithDialContext(helper.Dialer), } } else { + // connhelper.GetConnectionHelper already parsed the host without error + url, _ := url.Parse(host) opt = []client.Opt{ client.WithHost(host), } + switch url.Scheme { + case "", "tls", "http", "https": + if (url.Scheme == "https" || url.Scheme == "tls") && cfg.TLS == nil { + return nil, fmt.Errorf("TLS config is not set when using %s:// host", url.Scheme) + } + + dial = func(ctx context.Context) (net.Conn, error) { + var dialer net.Dialer + return dialer.DialContext(ctx, "tcp", url.Host) + } + + opt = append(opt, client.WithDialContext(func(ctx context.Context, _, _ string) (net.Conn, error) { + return dial(ctx) + })) + } } } @@ -212,7 +230,7 @@ func NewClient(cfg types.DockerProviderConfig, unique ...bool) (*SharedClient, e } func (c *SharedClient) GetHTTPClient() **http.Client { - return (**http.Client)(unsafe.Pointer(uintptr(unsafe.Pointer(c.Client)) + clientClientOffset)) + return (**http.Client)(unsafe.Add(unsafe.Pointer(c.Client), clientClientOffset)) } func (c *SharedClient) InterceptHTTPClient(intercept httputils.InterceptFunc) { @@ -279,6 +297,6 @@ func (c *SharedClient) unotel() { log.Debug().Str("host", c.DaemonHost()).Msgf("docker client transport is not an otelhttp.Transport: %T", httpClient.Transport) return } - transport := *(*http.RoundTripper)(unsafe.Pointer(uintptr(unsafe.Pointer(otelTransport)) + otelRtOffset)) + transport := *(*http.RoundTripper)(unsafe.Add(unsafe.Pointer(otelTransport), otelRtOffset)) httpClient.Transport = transport } diff --git a/internal/watcher/docker_watcher.go b/internal/watcher/docker_watcher.go index c5359210..472d1fd9 100644 --- a/internal/watcher/docker_watcher.go +++ b/internal/watcher/docker_watcher.go @@ -177,7 +177,7 @@ func checkConnection(ctx context.Context, client *docker.SharedClient) bool { defer cancel() err := client.CheckConnection(ctx) if err != nil { - log.Debug().Err(err).Msg("docker watcher: connection failed") + log.Debug().Err(err).Str("host", client.Address()).Msg("docker watcher: connection failed") return false } return true