diff --git a/client/client.go b/client/client.go index b5e2e40c4b..242bb4d48e 100644 --- a/client/client.go +++ b/client/client.go @@ -99,11 +99,9 @@ const DummyHost = "api.moby.localhost" // This version may be lower than the version of the api library module used. const MaxAPIVersion = "1.52" -// fallbackAPIVersion is the version to fallback to if API-version negotiation -// fails. This version is the highest version of the API before API-version -// negotiation was introduced. If negotiation fails (or no API version was -// included in the API response), we assume the API server uses the most -// recent version before negotiation was introduced. +// fallbackAPIVersion is the version to fall back to if API-version negotiation +// fails. API versions below this version are not supported by the client, +// and not considered when negotiating. const fallbackAPIVersion = "1.24" // Ensure that Client always implements APIClient. @@ -311,8 +309,7 @@ func (cli *Client) ClientVersion() string { // If the API server's ping response does not contain an API version, or if the // client did not get a successful ping response, it assumes it is connected with // an old daemon that does not support API version negotiation, in which case it -// downgrades to the latest version of the API before version negotiation was -// added (1.24). +// downgrades to the lowest supported API version. func (cli *Client) NegotiateAPIVersion(ctx context.Context) { if !cli.manualOverride { // Avoid concurrent modification of version-related fields @@ -337,10 +334,8 @@ func (cli *Client) NegotiateAPIVersion(ctx context.Context) { // ([EnvOverrideAPIVersion]) environment variable, or if the client is initialized // with a fixed version ([WithVersion]), no negotiation is performed. // -// If the API server's ping response does not contain an API version, we assume -// we are connected with an old daemon without API version negotiation support, -// and downgrade to the latest version of the API before version negotiation was -// added (1.24). +// If the API server's ping response does not contain an API version, it falls +// back to the oldest API version supported. func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping) { if !cli.manualOverride { // Avoid concurrent modification of version-related fields @@ -355,8 +350,6 @@ func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping) { // API version from the ping response. func (cli *Client) negotiateAPIVersionPing(pingVersion string) { pingVersion = strings.TrimPrefix(pingVersion, "v") - - // default to the latest version before versioning headers existed if pingVersion == "" { pingVersion = fallbackAPIVersion } diff --git a/client/request.go b/client/request.go index 7c9102edf7..f5c2b956a0 100644 --- a/client/request.go +++ b/client/request.go @@ -303,9 +303,8 @@ func checkResponseErr(serverResp *http.Response) (retErr error) { daemonErr = errors.New(strings.TrimSpace(errorResponse.Message)) } } else { - // Fall back to returning the response as-is for API versions < 1.24 - // that didn't support JSON error responses, and for situations - // where a plain text error is returned. This branch may also catch + // Fall back to returning the response as-is for situations where a + // plain text error is returned. This branch may also catch // situations where a proxy is involved, returning a HTML response. daemonErr = errors.New(strings.TrimSpace(string(body))) } diff --git a/client/request_test.go b/client/request_test.go index d9065952f2..08e816dd1c 100644 --- a/client/request_test.go +++ b/client/request_test.go @@ -74,9 +74,9 @@ func TestSetHostHeader(t *testing.T) { } } -// TestPlainTextError tests the server returning an error in plain text for -// backwards compatibility with API versions <1.24. All other tests use -// errors returned as JSON +// TestPlainTextError tests the server returning an error in plain text. +// API versions < 1.24 returned plain text errors, but we may encounter +// other situations where a non-JSON error is returned. func TestPlainTextError(t *testing.T) { client, err := NewClientWithOpts(WithMockClient(plainTextErrorMock(http.StatusInternalServerError, "Server error"))) assert.NilError(t, err) diff --git a/vendor/github.com/moby/moby/client/client.go b/vendor/github.com/moby/moby/client/client.go index b5e2e40c4b..242bb4d48e 100644 --- a/vendor/github.com/moby/moby/client/client.go +++ b/vendor/github.com/moby/moby/client/client.go @@ -99,11 +99,9 @@ const DummyHost = "api.moby.localhost" // This version may be lower than the version of the api library module used. const MaxAPIVersion = "1.52" -// fallbackAPIVersion is the version to fallback to if API-version negotiation -// fails. This version is the highest version of the API before API-version -// negotiation was introduced. If negotiation fails (or no API version was -// included in the API response), we assume the API server uses the most -// recent version before negotiation was introduced. +// fallbackAPIVersion is the version to fall back to if API-version negotiation +// fails. API versions below this version are not supported by the client, +// and not considered when negotiating. const fallbackAPIVersion = "1.24" // Ensure that Client always implements APIClient. @@ -311,8 +309,7 @@ func (cli *Client) ClientVersion() string { // If the API server's ping response does not contain an API version, or if the // client did not get a successful ping response, it assumes it is connected with // an old daemon that does not support API version negotiation, in which case it -// downgrades to the latest version of the API before version negotiation was -// added (1.24). +// downgrades to the lowest supported API version. func (cli *Client) NegotiateAPIVersion(ctx context.Context) { if !cli.manualOverride { // Avoid concurrent modification of version-related fields @@ -337,10 +334,8 @@ func (cli *Client) NegotiateAPIVersion(ctx context.Context) { // ([EnvOverrideAPIVersion]) environment variable, or if the client is initialized // with a fixed version ([WithVersion]), no negotiation is performed. // -// If the API server's ping response does not contain an API version, we assume -// we are connected with an old daemon without API version negotiation support, -// and downgrade to the latest version of the API before version negotiation was -// added (1.24). +// If the API server's ping response does not contain an API version, it falls +// back to the oldest API version supported. func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping) { if !cli.manualOverride { // Avoid concurrent modification of version-related fields @@ -355,8 +350,6 @@ func (cli *Client) NegotiateAPIVersionPing(pingResponse types.Ping) { // API version from the ping response. func (cli *Client) negotiateAPIVersionPing(pingVersion string) { pingVersion = strings.TrimPrefix(pingVersion, "v") - - // default to the latest version before versioning headers existed if pingVersion == "" { pingVersion = fallbackAPIVersion } diff --git a/vendor/github.com/moby/moby/client/request.go b/vendor/github.com/moby/moby/client/request.go index 7c9102edf7..f5c2b956a0 100644 --- a/vendor/github.com/moby/moby/client/request.go +++ b/vendor/github.com/moby/moby/client/request.go @@ -303,9 +303,8 @@ func checkResponseErr(serverResp *http.Response) (retErr error) { daemonErr = errors.New(strings.TrimSpace(errorResponse.Message)) } } else { - // Fall back to returning the response as-is for API versions < 1.24 - // that didn't support JSON error responses, and for situations - // where a plain text error is returned. This branch may also catch + // Fall back to returning the response as-is for situations where a + // plain text error is returned. This branch may also catch // situations where a proxy is involved, returning a HTML response. daemonErr = errors.New(strings.TrimSpace(string(body))) }