This commit is contained in:
yusing
2026-01-07 15:29:39 +08:00
parent 63e69e71c3
commit 5ff6928b13
2 changed files with 21 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import (
"maps" "maps"
"net" "net"
"net/http" "net/http"
"net/url"
"reflect" "reflect"
"sync" "sync"
"sync/atomic" "sync/atomic"
@@ -169,9 +170,26 @@ func NewClient(cfg types.DockerProviderConfig, unique ...bool) (*SharedClient, e
client.WithDialContext(helper.Dialer), client.WithDialContext(helper.Dialer),
} }
} else { } else {
// connhelper.GetConnectionHelper already parsed the host without error
url, _ := url.Parse(host)
opt = []client.Opt{ opt = []client.Opt{
client.WithHost(host), 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 { 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) { 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) log.Debug().Str("host", c.DaemonHost()).Msgf("docker client transport is not an otelhttp.Transport: %T", httpClient.Transport)
return return
} }
transport := *(*http.RoundTripper)(unsafe.Pointer(uintptr(unsafe.Pointer(otelTransport)) + otelRtOffset)) transport := *(*http.RoundTripper)(unsafe.Add(unsafe.Pointer(otelTransport), otelRtOffset))
httpClient.Transport = transport httpClient.Transport = transport
} }

View File

@@ -177,7 +177,7 @@ func checkConnection(ctx context.Context, client *docker.SharedClient) bool {
defer cancel() defer cancel()
err := client.CheckConnection(ctx) err := client.CheckConnection(ctx)
if err != nil { 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 false
} }
return true return true