The CheckDuplicate option is no longer part of the current API; it's
only used by the client when connecting to old API versions, which need
to have this field set.
This patch:
- Removes the CheckDuplicate from the API documentation, as the API
describes the current version of the API (which does not have this
field).
- Moves the CheckDuplicate field to the CreateRequest type; this is
the type used for the network create request. The CheckDuplicate
is not an option that's set by the user, and set internally by
the client, so removing it from the CreateOptions struct moves
it entirely internal.
- Change the CheckDuplicate field to be a pointer; this makes the
"omitempty" become active, and the client will no longer include
the field in the request JSON unless it's set (API < 1.44).
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -10197,11 +10197,6 @@ paths: |
| 10197 | 10197 |
description: "The network's name." |
| 10198 | 10198 |
type: "string" |
| 10199 | 10199 |
example: "my_network" |
| 10200 |
- CheckDuplicate: |
|
| 10201 |
- description: | |
|
| 10202 |
- Deprecated: CheckDuplicate is now always enabled. |
|
| 10203 |
- type: "boolean" |
|
| 10204 |
- example: true |
|
| 10205 | 10200 |
Driver: |
| 10206 | 10201 |
description: "Name of the network driver plugin to use." |
| 10207 | 10202 |
type: "string" |
| ... | ... |
@@ -23,14 +23,14 @@ const ( |
| 23 | 23 |
type CreateRequest struct {
|
| 24 | 24 |
CreateOptions |
| 25 | 25 |
Name string // Name is the requested name of the network. |
| 26 |
-} |
|
| 27 | 26 |
|
| 28 |
-// CreateOptions holds options to create a network. |
|
| 29 |
-type CreateOptions struct {
|
|
| 30 | 27 |
// Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client |
| 31 | 28 |
// package to older daemons. |
| 32 |
- CheckDuplicate bool `json:",omitempty"` |
|
| 29 |
+ CheckDuplicate *bool `json:",omitempty"` |
|
| 30 |
+} |
|
| 33 | 31 |
|
| 32 |
+// CreateOptions holds options to create a network. |
|
| 33 |
+type CreateOptions struct {
|
|
| 34 | 34 |
Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`) |
| 35 | 35 |
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level). |
| 36 | 36 |
EnableIPv6 *bool `json:",omitempty"` // EnableIPv6 represents whether to enable IPv6. |
| ... | ... |
@@ -26,7 +26,8 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options netwo |
| 26 | 26 |
Name: name, |
| 27 | 27 |
} |
| 28 | 28 |
if versions.LessThan(cli.version, "1.44") {
|
| 29 |
- networkCreateRequest.CheckDuplicate = true //nolint:staticcheck // ignore SA1019: CheckDuplicate is deprecated since API v1.44. |
|
| 29 |
+ enabled := true |
|
| 30 |
+ networkCreateRequest.CheckDuplicate = &enabled //nolint:staticcheck // ignore SA1019: CheckDuplicate is deprecated since API v1.44. |
|
| 30 | 31 |
} |
| 31 | 32 |
|
| 32 | 33 |
serverResp, err := cli.post(ctx, "/networks/create", nil, networkCreateRequest, nil) |