api/types/network: CreateRequest: remove deprecated CheckDuplicate field

CheckDuplicate is removed in API v1.44, and no longer used by
daemons supporting that API version (v25.0.0-beta.1 and up)
regardless of the API version used, but it must be set to true
when sent to older daemons (see [moby@78479b1]).

This patch moves adding the field to the client through an ad-hoc struct
so that we don't have to carry the field in the API module.

We can remove this once daemon versions v24.0 and lower are no longer
expected to be used (when Mirantis Container Runtime v23 is EOL).
https://github.com/moby/moby/blob/v2.0.0-beta.0/project/BRANCHES-AND-TAGS.md.

This field was removed from API v1.44 and no longer used by daemons supporting
that API version (v25.0.0-beta.1 and up) regardless of the API version used,
but for older version of the daemon required this option to be set.

[moby@78479b1]: 78479b1915

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-09-17 14:07:10 +02:00
parent d0ac3c4eeb
commit 6d0551e13a
4 changed files with 40 additions and 14 deletions

View File

@@ -28,10 +28,6 @@ type CreateRequest struct {
ConfigFrom *ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. The specified network must be a config-only network; see [CreateOptions.ConfigOnly].
Options map[string]string // Options specifies the network-specific options to use for when creating the network.
Labels map[string]string // Labels holds metadata specific to the network being created.
// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client
// package to older daemons.
CheckDuplicate *bool `json:",omitempty"`
}
// ServiceInfo represents service parameters with the list of service's tasks

View File

@@ -34,12 +34,29 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options Netwo
Options: options.Options,
Labels: options.Labels,
}
var req any
if versions.LessThan(cli.version, "1.44") {
enabled := true
networkCreateRequest.CheckDuplicate = &enabled //nolint:staticcheck // ignore SA1019: CheckDuplicate is deprecated since API v1.44.
// CheckDuplicate is removed in API v1.44, and no longer used by
// daemons supporting that API version (v25.0.0-beta.1 and up)
// regardless of the API version used, but it must be set to true
// when sent to older daemons.
//
// TODO(thaJeztah) remove this once daemon versions v24.0 and lower are no
// longer expected to be used (when Mirantis Container Runtime v23
// is EOL); https://github.com/moby/moby/blob/v2.0.0-beta.0/project/BRANCHES-AND-TAGS.md
req = struct {
network.CreateRequest
CheckDuplicate bool
}{
CreateRequest: networkCreateRequest,
CheckDuplicate: true,
}
} else {
req = networkCreateRequest
}
resp, err := cli.post(ctx, "/networks/create", nil, networkCreateRequest, nil)
resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
defer ensureReaderClosed(resp)
if err != nil {
return network.CreateResponse{}, err

View File

@@ -28,10 +28,6 @@ type CreateRequest struct {
ConfigFrom *ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. The specified network must be a config-only network; see [CreateOptions.ConfigOnly].
Options map[string]string // Options specifies the network-specific options to use for when creating the network.
Labels map[string]string // Labels holds metadata specific to the network being created.
// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client
// package to older daemons.
CheckDuplicate *bool `json:",omitempty"`
}
// ServiceInfo represents service parameters with the list of service's tasks

View File

@@ -34,12 +34,29 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options Netwo
Options: options.Options,
Labels: options.Labels,
}
var req any
if versions.LessThan(cli.version, "1.44") {
enabled := true
networkCreateRequest.CheckDuplicate = &enabled //nolint:staticcheck // ignore SA1019: CheckDuplicate is deprecated since API v1.44.
// CheckDuplicate is removed in API v1.44, and no longer used by
// daemons supporting that API version (v25.0.0-beta.1 and up)
// regardless of the API version used, but it must be set to true
// when sent to older daemons.
//
// TODO(thaJeztah) remove this once daemon versions v24.0 and lower are no
// longer expected to be used (when Mirantis Container Runtime v23
// is EOL); https://github.com/moby/moby/blob/v2.0.0-beta.0/project/BRANCHES-AND-TAGS.md
req = struct {
network.CreateRequest
CheckDuplicate bool
}{
CreateRequest: networkCreateRequest,
CheckDuplicate: true,
}
} else {
req = networkCreateRequest
}
resp, err := cli.post(ctx, "/networks/create", nil, networkCreateRequest, nil)
resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
defer ensureReaderClosed(resp)
if err != nil {
return network.CreateResponse{}, err