Auto-negotiate Docker API version

This commit is contained in:
Kevin Pollet 2025-11-12 16:32:06 +01:00 committed by GitHub
parent effca0a603
commit 058b194604
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -33,14 +33,6 @@ import (
"github.com/traefik/traefik/v2/pkg/version"
)
const (
// DockerAPIVersion is a constant holding the version of the Provider API traefik will use.
DockerAPIVersion = "1.24"
// SwarmAPIVersion is a constant holding the version of the Provider API traefik will use.
SwarmAPIVersion = "1.24"
)
// DefaultTemplateRule The default template for the default rule.
const DefaultTemplateRule = "Host(`{{ normalize .Name }}`)"
@ -121,13 +113,10 @@ func (p *Provider) createClient() (client.APIClient, error) {
httpHeaders := map[string]string{
"User-Agent": "Traefik " + version.Version,
}
opts = append(opts, client.WithHTTPHeaders(httpHeaders))
apiVersion := DockerAPIVersion
if p.SwarmMode {
apiVersion = SwarmAPIVersion
}
opts = append(opts, client.WithVersion(apiVersion))
opts = append(opts,
client.FromEnv,
client.WithAPIVersionNegotiation(),
client.WithHTTPHeaders(httpHeaders))
return client.NewClientWithOpts(opts...)
}