mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
client: don't downgrade when failing to negotiate
Historically, the client would downgrade to API v1.24 when failing to negotiate as this was the API version from before API-version negotiation was introduced. Given that those daemons are EOL and those API versions no longer supported, we should not fall back to an older API version, and just continue using the latest / current version. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -313,19 +313,12 @@ func (cli *Client) ClientVersion() string {
|
||||
}
|
||||
|
||||
// negotiateAPIVersion updates the version to match the API version from
|
||||
// the ping response. It falls back to the lowest version supported if the
|
||||
// API version is empty.
|
||||
// the ping response.
|
||||
//
|
||||
// It returns an error if version is invalid, or lower than the minimum
|
||||
// supported API version in which case the client's API version is not
|
||||
// updated, and negotiation is not marked as completed.
|
||||
func (cli *Client) negotiateAPIVersion(pingVersion string) error {
|
||||
pingVersion = strings.TrimPrefix(pingVersion, "v")
|
||||
if pingVersion == "" {
|
||||
// TODO(thaJeztah): consider returning an error on empty value or not falling back; see https://github.com/moby/moby/pull/51119#discussion_r2413148487
|
||||
pingVersion = MinAPIVersion
|
||||
}
|
||||
|
||||
var err error
|
||||
pingVersion, err = parseAPIVersion(pingVersion)
|
||||
if err != nil {
|
||||
|
||||
@@ -300,12 +300,10 @@ func TestNegotiateAPIVersion(t *testing.T) {
|
||||
expectedVersion: "1.51",
|
||||
},
|
||||
{
|
||||
// client should downgrade to the last version before version
|
||||
// negotiation was added (1.24) if the daemon does not report
|
||||
// a version.
|
||||
// client should not downgrade if the daemon didn't report a version.
|
||||
doc: "downgrade legacy",
|
||||
pingVersion: "",
|
||||
expectedVersion: MinAPIVersion,
|
||||
expectedVersion: MaxAPIVersion,
|
||||
},
|
||||
{
|
||||
// client should not downgrade to the version reported by the daemon
|
||||
|
||||
@@ -97,6 +97,11 @@ func (cli *Client) Ping(ctx context.Context, options PingOptions) (PingResult, e
|
||||
return ping, nil
|
||||
}
|
||||
|
||||
if ping.APIVersion == "" {
|
||||
cli.setAPIVersion(MaxAPIVersion)
|
||||
return ping, nil
|
||||
}
|
||||
|
||||
return ping, cli.negotiateAPIVersion(ping.APIVersion)
|
||||
}
|
||||
|
||||
|
||||
9
vendor/github.com/moby/moby/client/client.go
generated
vendored
9
vendor/github.com/moby/moby/client/client.go
generated
vendored
@@ -313,19 +313,12 @@ func (cli *Client) ClientVersion() string {
|
||||
}
|
||||
|
||||
// negotiateAPIVersion updates the version to match the API version from
|
||||
// the ping response. It falls back to the lowest version supported if the
|
||||
// API version is empty.
|
||||
// the ping response.
|
||||
//
|
||||
// It returns an error if version is invalid, or lower than the minimum
|
||||
// supported API version in which case the client's API version is not
|
||||
// updated, and negotiation is not marked as completed.
|
||||
func (cli *Client) negotiateAPIVersion(pingVersion string) error {
|
||||
pingVersion = strings.TrimPrefix(pingVersion, "v")
|
||||
if pingVersion == "" {
|
||||
// TODO(thaJeztah): consider returning an error on empty value or not falling back; see https://github.com/moby/moby/pull/51119#discussion_r2413148487
|
||||
pingVersion = MinAPIVersion
|
||||
}
|
||||
|
||||
var err error
|
||||
pingVersion, err = parseAPIVersion(pingVersion)
|
||||
if err != nil {
|
||||
|
||||
5
vendor/github.com/moby/moby/client/ping.go
generated
vendored
5
vendor/github.com/moby/moby/client/ping.go
generated
vendored
@@ -97,6 +97,11 @@ func (cli *Client) Ping(ctx context.Context, options PingOptions) (PingResult, e
|
||||
return ping, nil
|
||||
}
|
||||
|
||||
if ping.APIVersion == "" {
|
||||
cli.setAPIVersion(MaxAPIVersion)
|
||||
return ping, nil
|
||||
}
|
||||
|
||||
return ping, cli.negotiateAPIVersion(ping.APIVersion)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user