Browse code

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]: https://github.com/moby/moby/commit/78479b19158290e7338ceb3985bb809b83de5fd4

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/09/17 21:07:10
Showing 4 changed files
... ...
@@ -28,10 +28,6 @@ type CreateRequest struct {
28 28
 	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].
29 29
 	Options    map[string]string // Options specifies the network-specific options to use for when creating the network.
30 30
 	Labels     map[string]string // Labels holds metadata specific to the network being created.
31
-
32
-	// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client
33
-	// package to older daemons.
34
-	CheckDuplicate *bool `json:",omitempty"`
35 31
 }
36 32
 
37 33
 // ServiceInfo represents service parameters with the list of service's tasks
... ...
@@ -34,12 +34,29 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options Netwo
34 34
 		Options:    options.Options,
35 35
 		Labels:     options.Labels,
36 36
 	}
37
+
38
+	var req any
37 39
 	if versions.LessThan(cli.version, "1.44") {
38
-		enabled := true
39
-		networkCreateRequest.CheckDuplicate = &enabled //nolint:staticcheck // ignore SA1019: CheckDuplicate is deprecated since API v1.44.
40
+		// CheckDuplicate is removed in API v1.44, and no longer used by
41
+		// daemons supporting that API version (v25.0.0-beta.1 and up)
42
+		// regardless of the API version used, but it must be set to true
43
+		// when sent to older daemons.
44
+		//
45
+		// TODO(thaJeztah) remove this once daemon versions v24.0 and lower are no
46
+		//   longer expected to be used (when Mirantis Container Runtime v23
47
+		//   is EOL);  https://github.com/moby/moby/blob/v2.0.0-beta.0/project/BRANCHES-AND-TAGS.md
48
+		req = struct {
49
+			network.CreateRequest
50
+			CheckDuplicate bool
51
+		}{
52
+			CreateRequest:  networkCreateRequest,
53
+			CheckDuplicate: true,
54
+		}
55
+	} else {
56
+		req = networkCreateRequest
40 57
 	}
41 58
 
42
-	resp, err := cli.post(ctx, "/networks/create", nil, networkCreateRequest, nil)
59
+	resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
43 60
 	defer ensureReaderClosed(resp)
44 61
 	if err != nil {
45 62
 		return network.CreateResponse{}, err
... ...
@@ -28,10 +28,6 @@ type CreateRequest struct {
28 28
 	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].
29 29
 	Options    map[string]string // Options specifies the network-specific options to use for when creating the network.
30 30
 	Labels     map[string]string // Labels holds metadata specific to the network being created.
31
-
32
-	// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client
33
-	// package to older daemons.
34
-	CheckDuplicate *bool `json:",omitempty"`
35 31
 }
36 32
 
37 33
 // ServiceInfo represents service parameters with the list of service's tasks
... ...
@@ -34,12 +34,29 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options Netwo
34 34
 		Options:    options.Options,
35 35
 		Labels:     options.Labels,
36 36
 	}
37
+
38
+	var req any
37 39
 	if versions.LessThan(cli.version, "1.44") {
38
-		enabled := true
39
-		networkCreateRequest.CheckDuplicate = &enabled //nolint:staticcheck // ignore SA1019: CheckDuplicate is deprecated since API v1.44.
40
+		// CheckDuplicate is removed in API v1.44, and no longer used by
41
+		// daemons supporting that API version (v25.0.0-beta.1 and up)
42
+		// regardless of the API version used, but it must be set to true
43
+		// when sent to older daemons.
44
+		//
45
+		// TODO(thaJeztah) remove this once daemon versions v24.0 and lower are no
46
+		//   longer expected to be used (when Mirantis Container Runtime v23
47
+		//   is EOL);  https://github.com/moby/moby/blob/v2.0.0-beta.0/project/BRANCHES-AND-TAGS.md
48
+		req = struct {
49
+			network.CreateRequest
50
+			CheckDuplicate bool
51
+		}{
52
+			CreateRequest:  networkCreateRequest,
53
+			CheckDuplicate: true,
54
+		}
55
+	} else {
56
+		req = networkCreateRequest
40 57
 	}
41 58
 
42
-	resp, err := cli.post(ctx, "/networks/create", nil, networkCreateRequest, nil)
59
+	resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
43 60
 	defer ensureReaderClosed(resp)
44 61
 	if err != nil {
45 62
 		return network.CreateResponse{}, err