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:
Sebastiaan van Stijn
2025-11-14 16:26:06 +01:00
parent 189942570a
commit 04ab3d562c
5 changed files with 14 additions and 20 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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)
}