client: ServiceCreate, ServiceUpdate: omit "version" header on API >= 1.30
The "version" header was added inc0afd9c873
, but used the wrong information to get the API version. This issue was fixed ina9d20916c3
, which switched the API handler code to get the API version from the context. That change is part of Docker Engine 20.10 (API v1.30 and up) This patch updates the code to only set the header on APi v1.29 and older, as it's not used by newer API versions. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
462d6ef826
commit
e4ce676d3d
2 changed files with 22 additions and 15 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -17,13 +18,6 @@ import (
|
|||
// ServiceCreate creates a new service.
|
||||
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error) {
|
||||
var response types.ServiceCreateResponse
|
||||
headers := map[string][]string{
|
||||
"version": {cli.version},
|
||||
}
|
||||
|
||||
if options.EncodedRegistryAuth != "" {
|
||||
headers[registry.AuthHeader] = []string{options.EncodedRegistryAuth}
|
||||
}
|
||||
|
||||
// Make sure containerSpec is not nil when no runtime is set or the runtime is set to container
|
||||
if service.TaskTemplate.ContainerSpec == nil && (service.TaskTemplate.Runtime == "" || service.TaskTemplate.Runtime == swarm.RuntimeContainer) {
|
||||
|
@ -53,6 +47,16 @@ func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec,
|
|||
}
|
||||
}
|
||||
|
||||
headers := map[string][]string{}
|
||||
if versions.LessThan(cli.version, "1.30") {
|
||||
// the custom "version" header was used by engine API before 20.10
|
||||
// (API 1.30) to switch between client- and server-side lookup of
|
||||
// image digests.
|
||||
headers["version"] = []string{cli.version}
|
||||
}
|
||||
if options.EncodedRegistryAuth != "" {
|
||||
headers[registry.AuthHeader] = []string{options.EncodedRegistryAuth}
|
||||
}
|
||||
resp, err := cli.post(ctx, "/services/create", nil, service, headers)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
)
|
||||
|
||||
// ServiceUpdate updates a Service. The version number is required to avoid conflicting writes.
|
||||
|
@ -19,14 +20,6 @@ func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version
|
|||
response = types.ServiceUpdateResponse{}
|
||||
)
|
||||
|
||||
headers := map[string][]string{
|
||||
"version": {cli.version},
|
||||
}
|
||||
|
||||
if options.EncodedRegistryAuth != "" {
|
||||
headers[registry.AuthHeader] = []string{options.EncodedRegistryAuth}
|
||||
}
|
||||
|
||||
if options.RegistryAuthFrom != "" {
|
||||
query.Set("registryAuthFrom", options.RegistryAuthFrom)
|
||||
}
|
||||
|
@ -60,6 +53,16 @@ func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version
|
|||
}
|
||||
}
|
||||
|
||||
headers := map[string][]string{}
|
||||
if versions.LessThan(cli.version, "1.30") {
|
||||
// the custom "version" header was used by engine API before 20.10
|
||||
// (API 1.30) to switch between client- and server-side lookup of
|
||||
// image digests.
|
||||
headers["version"] = []string{cli.version}
|
||||
}
|
||||
if options.EncodedRegistryAuth != "" {
|
||||
headers[registry.AuthHeader] = []string{options.EncodedRegistryAuth}
|
||||
}
|
||||
resp, err := cli.post(ctx, "/services/"+serviceID+"/update", query, service, headers)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue