E59A api: remove unused DefaultVersion, MinSupportedAPIVersion consts · moby/moby@c1c38e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1c38e8

Browse files
thaJeztahaustinvazquez
authored andcommitted
api: remove unused DefaultVersion, MinSupportedAPIVersion consts
These consts are no longer used, and separate consts were added in both the client and daemon packages; - client: 41da570 - daemon: a632b84 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 4534924 commit c1c38e8

File tree

22 files changed

+77
-13623
lines changed

22 files changed

+77
-13623
lines changed

api/common.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

client/client.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,14 @@ import (
9191
// [Go stdlib]: https://github.com/golang/go/blob/6244b1946bc2101b01955468f1be502dbadd6807/src/net/http/transport.go#L558-L569
9292
const DummyHost = "api.moby.localhost"
9393

94-
// DefaultAPIVersion is the highest REST API version supported by the client.
94+
// MaxAPIVersion is the highest REST API version supported by the client.
9595
// If API-version negotiation is enabled (see [WithAPIVersionNegotiation],
9696
// [Client.NegotiateAPIVersion]), the client may downgrade its API version.
9797
// Similarly, the [WithVersion] and [WithVersionFromEnv] allow overriding
9898
// the version.
9999
//
100-
// This version may be lower than the [api.DefaultVersion], which is the default
101-
// (and highest supported) version of the api library module used.
102-
const DefaultAPIVersion = "1.52"
100+
// This version may be lower than the version of the api library module used.
101+
const MaxAPIVersion = "1.52"
103102

104103
// fallbackAPIVersion is the version to fallback to if API-version negotiation
105104
// fails. This version is the highest version of the API before API-version
@@ -208,7 +207,7 @@ func NewClientWithOpts(ops ...Opt) (*Client, error) {
208207
}
209208
c := &Client{
210209
host: DefaultDockerHost,
211-
version: DefaultAPIVersion,
210+
version: MaxAPIVersion,
212211
client: client,
213212
proto: hostURL.Scheme,
214213
addr: hostURL.Host,
@@ -391,7 +390,7 @@ func (cli *Client) negotiateAPIVersionPing(pingResponse types.Ping) {
391390

392391
// if the client is not initialized with a version, start with the latest supported version
393392
if cli.version == "" {
394-
cli.version = DefaultAPIVersion
393+
cli.version = MaxAPIVersion
395394
}
396395

397396
// if server version is lower than the client version, downgrade

client/client_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
2929
{
3030
doc: "default api version",
3131
envs: map[string]string{},
32-
expectedVersion: DefaultAPIVersion,
32+
expectedVersion: MaxAPIVersion,
3333
},
3434
{
3535
doc: "invalid cert path",
@@ -43,23 +43,23 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
4343
envs: map[string]string{
4444
"DOCKER_CERT_PATH": "testdata/",
4545
},
46-
expectedVersion: DefaultAPIVersion,
46+
expectedVersion: MaxAPIVersion,
4747
},
4848
{
4949
doc: "default api version with cert path and tls verify",
5050
envs: map[string]string{
5151
"DOCKER_CERT_PATH": "testdata/",
5252
"DOCKER_TLS_VERIFY": "1",
5353
},
54-
expectedVersion: DefaultAPIVersion,
54+
expectedVersion: MaxAPIVersion,
5555
},
5656
{
5757
doc: "default api version with cert path and host",
5858
envs: map[string]string{
5959
"DOCKER_CERT_PATH": "testdata/",
6060
"DOCKER_HOST": "https://notaunixsocket",
6161
},
62-
expectedVersion: DefaultAPIVersion,
62+
expectedVersion: MaxAPIVersion,
6363
},
6464
{
6565
doc: "invalid docker host",
@@ -73,7 +73,7 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {
7373
envs: map[string]string{
7474
"DOCKER_HOST": "invalid://url",
7575
},
76-
expectedVersion: DefaultAPIVersion,
76+
expectedVersion: MaxAPIVersion,
7777
},
7878
{
7979
doc: "override api version",
@@ -116,17 +116,17 @@ func TestGetAPIPath(t *testing.T) {
116116
}{
117117
{
118118
path: "/containers/json",
119-
expected: "/v" + DefaultAPIVersion + "/containers/json",
119+
expected: "/v" + MaxAPIVersion + "/containers/json",
120120
},
121121
{
122122
path: "/containers/json",
123123
query: url.Values{},
124-
expected: "/v" + DefaultAPIVersion + "/containers/json",
124+
expected: "/v" + MaxAPIVersion + "/containers/json",
125125
},
126126
{
127127
path: "/containers/json",
128128
query: url.Values{"s": []string{"c"}},
129-
expected: "/v" + DefaultAPIVersion + "/containers/json?s=c",
129+
expected: "/v" + MaxAPIVersion + "/containers/json?s=c",
130130
},
131131
{
132132
version: "1.22",
@@ -234,7 +234,7 @@ func TestNewClientWithOpsFromEnvSetsDefaultVersion(t *testing.T) {
234234

235235
client, err := NewClientWithOpts(FromEnv)
236236
assert.NilError(t, err)
237-
assert.Check(t, is.Equal(client.ClientVersion(), DefaultAPIVersion))
237+
assert.Check(t, is.Equal(client.ClientVersion(), MaxAPIVersion))
238238

239239
const expected = "1.22"
240240
t.Setenv("DOCKER_API_VERSION", expected)
@@ -374,8 +374,8 @@ func TestNegotiateAPIVersionAutomatic(t *testing.T) {
374374
)
375375
assert.NilError(t, err)
376376

377-
// Client defaults to use DefaultAPIVersion before version-negotiation.
378-
expected := DefaultAPIVersion
377+
// Client defaults to use MaxAPIVersion before version-negotiation.
378+
expected := MaxAPIVersion
379379
assert.Check(t, is.Equal(client.ClientVersion(), expected))
380380

381381
// First request should trigger negotiation
@@ -422,7 +422,7 @@ func TestCustomAPIVersion(t *testing.T) {
422422
}{
423423
{
424424
version: "",
425-
expected: DefaultAPIVersion,
425+
expected: MaxAPIVersion,
426426
},
427427
{
428428
version: "1.0",
@@ -434,7 +434,7 @@ func TestCustomAPIVersion(t *testing.T) {
434434
},
435435
{
436436
version: "v",
437-
expected: DefaultAPIVersion,
437+
expected: MaxAPIVersion,
438438
},
439439
{
440440
version: "v1.0",

client/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func WithTLSClientConfigFromEnv() Opt {
197197
//
198198
// WithVersion does not validate if the client supports the given version,
199199
// and callers should verify if the version is in the correct format and
200-
// lower than the maximum supported version as defined by [DefaultAPIVersion].
200+
// lower than the maximum supported version as defined by [MaxAPIVersion].
201201
func WithVersion(version string) Opt {
202202
return func(c *Client) error {
203203
if v := strings.TrimPrefix(version, "v"); v != "" {
@@ -215,7 +215,7 @@ func WithVersion(version string) Opt {
215215
//
216216
// WithVersion does not validate if the client supports the given version,
217217
// and callers should verify if the version is in the correct format and
218-
// lower than the maximum supported version as defined by [DefaultAPIVersion].
218+
// lower than the maximum supported version as defined by [MaxAPIVersion].
219219
func WithVersionFromEnv() Opt {
220220
return func(c *Client) error {
221221
return WithVersion(os.Getenv(EnvOverrideAPIVersion))(c)

client/options_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestOptionWithVersionFromEnv(t *testing.T) {
4949
c, err := NewClientWithOpts(WithVersionFromEnv())
5050
assert.NilError(t, err)
5151
assert.Check(t, c.client != nil)
52-
assert.Check(t, is.Equal(c.version, DefaultAPIVersion))
52+
assert.Check(t, is.Equal(c.version, MaxAPIVersion))
5353
assert.Check(t, is.Equal(c.manualOverride, false))
5454

5555
t.Setenv("DOCKER_API_VERSION", "2.9999")

daemon/command/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ func initMiddlewares(_ context.Context, s *apiserver.Server, cfg *config.Config,
742742
exp := middleware.NewExperimentalMiddleware(cfg.Experimental)
743743
s.UseMiddleware(exp)
744744

745-
vm, err := middleware.NewVersionMiddleware(dockerversion.Version, config.DefaultAPIVersion, cfg.MinAPIVersion)
745+
vm, err := middleware.NewVersionMiddleware(dockerversion.Version, config.MaxAPIVersion, cfg.MinAPIVersion)
746746
if err != nil {
747747
return nil, err
748748
}

daemon/config/config.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"dario.cat/mergo"
1515
"github.com/containerd/log"
16-
"github.com/moby/moby/api"
1716
"github.com/moby/moby/api/types/versions"
1817
dopts "github.com/moby/moby/v2/daemon/internal/opts"
1918
"github.com/moby/moby/v2/daemon/pkg/opts"
@@ -56,16 +55,15 @@ const (
5655
DefaultContainersNamespace = "moby"
5756
// DefaultPluginNamespace is the name of the default containerd namespace used for plugins.
5857
DefaultPluginNamespace = "plugins.moby"
59-
// DefaultAPIVersion is the highest REST API version supported by the daemon.
58+
// MaxAPIVersion is the highest REST API version supported by the daemon.
6059
//
61-
// This version may be lower than the [api.DefaultVersion], which is the default
62-
// (and highest supported) version of the api library module used.
63-
DefaultAPIVersion = "1.52"
64-
// defaultMinAPIVersion is the minimum API version supported by the API.
60+
// This version may be lower than the version of the api library module used.
61+
MaxAPIVersion = "1.52"
62+
// MinAPIVersion is the minimum API version supported by the API.
6563
// This version can be overridden through the "DOCKER_MIN_API_VERSION"
6664
// environment variable. It currently defaults to the minimum API version
67-
// supported by the API server.
68-
defaultMinAPIVersion = api.MinSupportedAPIVersion
65+
// implemented in the API module.
66+
MinAPIVersion = "1.24"
6967
// SeccompProfileDefault is the built-in default seccomp profile.
7068
SeccompProfileDefault = "builtin"
7169
// SeccompProfileUnconfined is a special profile name for seccomp to use an
@@ -342,7 +340,7 @@ func New() (*Config, error) {
342340
ContainerdPluginNamespace: DefaultPluginNamespace,
343341
Features: make(map[string]bool),
344342
DefaultRuntime: StockRuntimeName,
345-
MinAPIVersion: defaultMinAPIVersion,
343+
MinAPIVersion: MinAPIVersion,
346344
},
347345
}
348346

@@ -676,11 +674,11 @@ func ValidateMinAPIVersion(ver string) error {
676674
if strings.EqualFold(ver[0:1], "v") {
677675
return errors.New(`API version must be provided without "v" prefix`)
678676
}
679-
if versions.LessThan(ver, defaultMinAPIVersion) {
680-
return errors.Errorf(`minimum supported API version is %s: %s`, defaultMinAPIVersion, ver)
677+
if versions.LessThan(ver, MinAPIVersion) {
678+
return errors.Errorf(`minimum supported API version is %s: %s`, MinAPIVersion, ver)
681679
}
682-
if versions.GreaterThan(ver, DefaultAPIVersion) {
683-
return errors.Errorf(`maximum supported API version is %s: %s`, DefaultAPIVersion, ver)
680+
if versions.GreaterThan(ver, MaxAPIVersion) {
681+
return errors.Errorf(`maximum supported API version is %s: %s`, MaxAPIVersion, ver)
684682
}
685683
return nil
686684
}

daemon/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ func TestValidateMinAPIVersion(t *testing.T) {
633633
},
634634
{
635635
doc: "current version",
636-
input: DefaultAPIVersion,
636+
input: MaxAPIVersion,
637637
},
638638
}
639639

daemon/info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (daemon *Daemon) SystemVersion(ctx context.Context) (types.Version, error)
114114
Version: dockerversion.Version,
115115
Details: map[string]string{
116116
"GitCommit": dockerversion.GitCommit,
117-
"ApiVersion": config.DefaultAPIVersion,
117+
"ApiVersion": config.MaxAPIVersion,
118118
"MinAPIVersion": cfg.MinAPIVersion,
119119
"GoVersion": runtime.Version(),
120120
"Os": runtime.GOOS,
@@ -129,7 +129,7 @@ func (daemon *Daemon) SystemVersion(ctx context.Context) (types.Version, error)
129129
// Populate deprecated fields for older clients
130130
Version: dockerversion.Version,
131131
GitCommit: dockerversion.GitCommit,
132-
APIVersion: config.DefaultAPIVersion,
132+
APIVersion: config.MaxAPIVersion,
133133
MinAPIVersion: cfg.MinAPIVersion,
134134
GoVersion: runtime.Version(),
135135
Os: runtime.GOOS,

daemon/server/middleware/version.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77
"runtime"
88

9-
"github.com/moby/moby/api"
109
"github.com/moby/moby/api/types/versions"
1110
"github.com/moby/moby/v2/daemon/config"
1211
"github.com/moby/moby/v2/daemon/server/httputils"
@@ -19,7 +18,7 @@ type VersionMiddleware struct {
1918

2019
// defaultAPIVersion is the default API version provided by the API server,
2120
// specified as "major.minor". It is usually configured to the latest API
22-
// version [config.DefaultAPIVersion] supported by the daemon.
21+
// version [config.MaxAPIVersion] supported by the daemon.
2322
//
2423
// API requests for API versions greater than this version are rejected by
2524
// the server and produce a [versionUnsupportedError].
@@ -35,11 +34,11 @@ type VersionMiddleware struct {
3534

3635
// NewVersionMiddleware creates a VersionMiddleware with the given versions.
3736
func NewVersionMiddleware(serverVersion, defaultAPIVersion, minAPIVersion string) (*VersionMiddleware, error) {
38-
if versions.LessThan(defaultAPIVersion, api.MinSupportedAPIVersion) || versions.GreaterThan(defaultAPIVersion, config.DefaultAPIVersion) {
39-
return nil, fmt.Errorf("invalid default API version (%s): must be between %s and %s", defaultAPIVersion, api.MinSupportedAPIVersion, config.DefaultAPIVersion)
37+
if versions.LessThan(defaultAPIVersion, config.MinAPIVersion) || versions.GreaterThan(defaultAPIVersion, config.MaxAPIVersion) {
38+
return nil, fmt.Errorf("invalid default API version (%s): must be between %s and %s", defaultAPIVersion, config.MinAPIVersion, config.MaxAPIVersion)
4039
}
41-
if versions.LessThan(minAPIVersion, api.MinSupportedAPIVersion) || versions.GreaterThan(minAPIVersion, config.DefaultAPIVersion) {
42-
return nil, fmt.Errorf("invalid minimum API version (%s): must be between %s and %s", minAPIVersion, api.MinSupportedAPIVersion, config.DefaultAPIVersion)
40+
if versions.LessThan(minAPIVersion, config.MinAPIVersion) || versions.GreaterThan(minAPIVersion, config.MaxAPIVersion) {
41+
return nil, fmt.Errorf("invalid minimum API version (%s): must be between %s and %s", minAPIVersion, config.MinAPIVersion, config.MaxAPIVersion)
4342
}
4443
if versions.GreaterThan(minAPIVersion, defaultAPIVersion) {
4544
return nil, fmt.Errorf("invalid API version: the minimum API version (%s) is higher than the default version (%s)", minAPIVersion, defaultAPIVersion)

0 commit comments

Comments
 (0)
0