diff --git a/client/client.go b/client/client.go index abe85457f3..0567ba11d4 100644 --- a/client/client.go +++ b/client/client.go @@ -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 { diff --git a/client/client_test.go b/client/client_test.go index b7aad6fca9..9b53167eec 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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 diff --git a/client/ping.go b/client/ping.go index 5d4b85fe59..d315e4b98b 100644 --- a/client/ping.go +++ b/client/ping.go @@ -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) } diff --git a/vendor/github.com/moby/moby/client/client.go b/vendor/github.com/moby/moby/client/client.go index abe85457f3..0567ba11d4 100644 --- a/vendor/github.com/moby/moby/client/client.go +++ b/vendor/github.com/moby/moby/client/client.go @@ -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 { diff --git a/vendor/github.com/moby/moby/client/ping.go b/vendor/github.com/moby/moby/client/ping.go index 5d4b85fe59..d315e4b98b 100644 --- a/vendor/github.com/moby/moby/client/ping.go +++ b/vendor/github.com/moby/moby/client/ping.go @@ -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) }