Merge pull request #7604 from roidelapluie/swarmsocket
Docker swarm: enable unix socket
This commit is contained in:
commit
79620c78db
|
@ -88,16 +88,12 @@ type Discovery struct {
|
||||||
|
|
||||||
// NewDiscovery returns a new Discovery which periodically refreshes its targets.
|
// NewDiscovery returns a new Discovery which periodically refreshes its targets.
|
||||||
func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
|
func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
|
||||||
|
var err error
|
||||||
d := &Discovery{
|
d := &Discovery{
|
||||||
port: conf.Port,
|
port: conf.Port,
|
||||||
role: conf.Role,
|
role: conf.Role,
|
||||||
}
|
}
|
||||||
|
|
||||||
rt, err := config_util.NewRoundTripperFromConfig(conf.HTTPClientConfig, "dockerswarm_sd", false)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is used in tests. In normal situations, it is set when Unmarshaling.
|
// This is used in tests. In normal situations, it is set when Unmarshaling.
|
||||||
if conf.url == nil {
|
if conf.url == nil {
|
||||||
conf.url, err = url.Parse(conf.Host)
|
conf.url, err = url.Parse(conf.Host)
|
||||||
|
@ -106,15 +102,29 @@ func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d.client, err = client.NewClientWithOpts(
|
opts := []client.Opt{
|
||||||
client.WithHost(conf.Host),
|
client.WithHost(conf.Host),
|
||||||
|
client.WithAPIVersionNegotiation(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// There are other protocols than HTTP supported by the Docker daemon, like
|
||||||
|
// unix, which are not supported by the HTTP client. Passing HTTP client
|
||||||
|
// options to the Docker client makes those non-HTTP requests fail.
|
||||||
|
if conf.url.Scheme == "http" || conf.url.Scheme == "https" {
|
||||||
|
rt, err := config_util.NewRoundTripperFromConfig(conf.HTTPClientConfig, "dockerswarm_sd", false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
opts = append(opts,
|
||||||
client.WithHTTPClient(&http.Client{
|
client.WithHTTPClient(&http.Client{
|
||||||
Transport: rt,
|
Transport: rt,
|
||||||
Timeout: time.Duration(conf.RefreshInterval),
|
Timeout: time.Duration(conf.RefreshInterval),
|
||||||
}),
|
}),
|
||||||
client.WithScheme(conf.url.Scheme),
|
client.WithScheme(conf.url.Scheme),
|
||||||
client.WithAPIVersionNegotiation(),
|
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
d.client, err = client.NewClientWithOpts(opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error setting up docker swarm client: %w", err)
|
return nil, fmt.Errorf("error setting up docker swarm client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue