mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: export fallbackAPIVersion as MinAPIVersion
Export the const and rename it to better reflect its intent. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -110,10 +110,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 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.44"
|
||||
// MinAPIVersion is the minimum API version supported by the client. API versions
|
||||
// below this version are not considered when performing API-version negotiation.
|
||||
const MinAPIVersion = "1.44"
|
||||
|
||||
// Ensure that Client always implements APIClient.
|
||||
var _ APIClient = &Client{}
|
||||
@@ -312,9 +311,9 @@ 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 = fallbackAPIVersion
|
||||
} else if versions.LessThan(pingVersion, fallbackAPIVersion) {
|
||||
return cerrdefs.ErrInvalidArgument.WithMessage(fmt.Sprintf("API version %s is not supported by this client: the minimum supported API version is %s", pingVersion, fallbackAPIVersion))
|
||||
pingVersion = MinAPIVersion
|
||||
} else if versions.LessThan(pingVersion, MinAPIVersion) {
|
||||
return cerrdefs.ErrInvalidArgument.WithMessage(fmt.Sprintf("API version %s is not supported by this client: the minimum supported API version is %s", pingVersion, MinAPIVersion))
|
||||
}
|
||||
|
||||
// if the client is not initialized with a version, start with the latest supported version
|
||||
|
||||
@@ -254,7 +254,7 @@ func TestNegotiateAPIVersionEmpty(t *testing.T) {
|
||||
|
||||
// if no version from server, expect the earliest
|
||||
// version before APIVersion was implemented
|
||||
const expected = fallbackAPIVersion
|
||||
const expected = MinAPIVersion
|
||||
|
||||
client, err := New(FromEnv,
|
||||
WithAPIVersionNegotiation(),
|
||||
@@ -306,7 +306,7 @@ func TestNegotiateAPIVersion(t *testing.T) {
|
||||
// a version.
|
||||
doc: "downgrade legacy",
|
||||
pingVersion: "",
|
||||
expectedVersion: fallbackAPIVersion,
|
||||
expectedVersion: MinAPIVersion,
|
||||
},
|
||||
{
|
||||
// client should not downgrade to the version reported by the daemon
|
||||
@@ -314,7 +314,7 @@ func TestNegotiateAPIVersion(t *testing.T) {
|
||||
doc: "no downgrade old",
|
||||
pingVersion: "1.19",
|
||||
expectedVersion: MaxAPIVersion,
|
||||
expectedErr: "API version 1.19 is not supported by this client: the minimum supported API version is " + fallbackAPIVersion,
|
||||
expectedErr: "API version 1.19 is not supported by this client: the minimum supported API version is " + MinAPIVersion,
|
||||
},
|
||||
{
|
||||
// client should not upgrade to a newer version if a version was set,
|
||||
|
||||
13
vendor/github.com/moby/moby/client/client.go
generated
vendored
13
vendor/github.com/moby/moby/client/client.go
generated
vendored
@@ -110,10 +110,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 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.44"
|
||||
// MinAPIVersion is the minimum API version supported by the client. API versions
|
||||
// below this version are not considered when performing API-version negotiation.
|
||||
const MinAPIVersion = "1.44"
|
||||
|
||||
// Ensure that Client always implements APIClient.
|
||||
var _ APIClient = &Client{}
|
||||
@@ -312,9 +311,9 @@ 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 = fallbackAPIVersion
|
||||
} else if versions.LessThan(pingVersion, fallbackAPIVersion) {
|
||||
return cerrdefs.ErrInvalidArgument.WithMessage(fmt.Sprintf("API version %s is not supported by this client: the minimum supported API version is %s", pingVersion, fallbackAPIVersion))
|
||||
pingVersion = MinAPIVersion
|
||||
} else if versions.LessThan(pingVersion, MinAPIVersion) {
|
||||
return cerrdefs.ErrInvalidArgument.WithMessage(fmt.Sprintf("API version %s is not supported by this client: the minimum supported API version is %s", pingVersion, MinAPIVersion))
|
||||
}
|
||||
|
||||
// if the client is not initialized with a version, start with the latest supported version
|
||||
|
||||
Reference in New Issue
Block a user