Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
| ... | ... |
@@ -21,16 +21,7 @@ const ( |
| 21 | 21 |
|
| 22 | 22 |
// CreateRequest is the request message sent to the server for network create call. |
| 23 | 23 |
type CreateRequest struct {
|
| 24 |
- CreateOptions |
|
| 25 |
- Name string // Name is the requested name of the network. |
|
| 26 |
- |
|
| 27 |
- // Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client |
|
| 28 |
- // package to older daemons. |
|
| 29 |
- CheckDuplicate *bool `json:",omitempty"` |
|
| 30 |
-} |
|
| 31 |
- |
|
| 32 |
-// CreateOptions holds options to create a network. |
|
| 33 |
-type CreateOptions struct {
|
|
| 24 |
+ Name string // Name is the requested name of the network. |
|
| 34 | 25 |
Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`) |
| 35 | 26 |
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level). |
| 36 | 27 |
EnableIPv4 *bool `json:",omitempty"` // EnableIPv4 represents whether to enable IPv4. |
| ... | ... |
@@ -43,6 +34,10 @@ type CreateOptions struct {
|
| 43 | 43 |
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]. |
| 44 | 44 |
Options map[string]string // Options specifies the network-specific options to use for when creating the network. |
| 45 | 45 |
Labels map[string]string // Labels holds metadata specific to the network being created. |
| 46 |
+ |
|
| 47 |
+ // Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client |
|
| 48 |
+ // package to older daemons. |
|
| 49 |
+ CheckDuplicate *bool `json:",omitempty"` |
|
| 46 | 50 |
} |
| 47 | 51 |
|
| 48 | 52 |
// Inspect is the body of the "get network" http response message. |
| ... | ... |
@@ -129,7 +129,7 @@ type ImageAPIClient interface {
|
| 129 | 129 |
// NetworkAPIClient defines API client methods for the networks |
| 130 | 130 |
type NetworkAPIClient interface {
|
| 131 | 131 |
NetworkConnect(ctx context.Context, network, container string, config *network.EndpointSettings) error |
| 132 |
- NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) |
|
| 132 |
+ NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) |
|
| 133 | 133 |
NetworkDisconnect(ctx context.Context, network, container string, force bool) error |
| 134 | 134 |
NetworkInspect(ctx context.Context, network string, options NetworkInspectOptions) (network.Inspect, error) |
| 135 | 135 |
NetworkInspectWithRaw(ctx context.Context, network string, options NetworkInspectOptions) (network.Inspect, []byte, error) |
| ... | ... |
@@ -9,7 +9,7 @@ import ( |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 | 11 |
// NetworkCreate creates a new network in the docker host. |
| 12 |
-func (cli *Client) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) {
|
|
| 12 |
+func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) {
|
|
| 13 | 13 |
// Make sure we negotiated (if the client is configured to do so), |
| 14 | 14 |
// as code below contains API-version specific handling of options. |
| 15 | 15 |
// |
| ... | ... |
@@ -20,8 +20,19 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options netwo |
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
networkCreateRequest := network.CreateRequest{
|
| 23 |
- CreateOptions: options, |
|
| 24 |
- Name: name, |
|
| 23 |
+ Name: name, |
|
| 24 |
+ Driver: options.Driver, |
|
| 25 |
+ Scope: options.Scope, |
|
| 26 |
+ EnableIPv4: options.EnableIPv4, |
|
| 27 |
+ EnableIPv6: options.EnableIPv6, |
|
| 28 |
+ IPAM: options.IPAM, |
|
| 29 |
+ Internal: options.Internal, |
|
| 30 |
+ Attachable: options.Attachable, |
|
| 31 |
+ Ingress: options.Ingress, |
|
| 32 |
+ ConfigOnly: options.ConfigOnly, |
|
| 33 |
+ ConfigFrom: options.ConfigFrom, |
|
| 34 |
+ Options: options.Options, |
|
| 35 |
+ Labels: options.Labels, |
|
| 25 | 36 |
} |
| 26 | 37 |
if versions.LessThan(cli.version, "1.44") {
|
| 27 | 38 |
enabled := true |
| 28 | 39 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,19 @@ |
| 0 |
+package client |
|
| 1 |
+ |
|
| 2 |
+import "github.com/moby/moby/api/types/network" |
|
| 3 |
+ |
|
| 4 |
+// NetworkCreateOptions holds options to create a network. |
|
| 5 |
+type NetworkCreateOptions struct {
|
|
| 6 |
+ Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`) |
|
| 7 |
+ Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level). |
|
| 8 |
+ EnableIPv4 *bool // EnableIPv4 represents whether to enable IPv4. |
|
| 9 |
+ EnableIPv6 *bool // EnableIPv6 represents whether to enable IPv6. |
|
| 10 |
+ IPAM *network.IPAM // IPAM is the network's IP Address Management. |
|
| 11 |
+ Internal bool // Internal represents if the network is used internal only. |
|
| 12 |
+ Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. |
|
| 13 |
+ Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster. |
|
| 14 |
+ ConfigOnly bool // ConfigOnly creates a config-only network. Config-only networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services. |
|
| 15 |
+ ConfigFrom *network.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]. |
|
| 16 |
+ Options map[string]string // Options specifies the network-specific options to use for when creating the network. |
|
| 17 |
+ Labels map[string]string // Labels holds metadata specific to the network being created. |
|
| 18 |
+} |
| ... | ... |
@@ -21,7 +21,7 @@ func TestNetworkCreateError(t *testing.T) {
|
| 21 | 21 |
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), |
| 22 | 22 |
} |
| 23 | 23 |
|
| 24 |
- _, err := client.NetworkCreate(context.Background(), "mynetwork", network.CreateOptions{})
|
|
| 24 |
+ _, err := client.NetworkCreate(context.Background(), "mynetwork", NetworkCreateOptions{})
|
|
| 25 | 25 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) |
| 26 | 26 |
} |
| 27 | 27 |
|
| ... | ... |
@@ -33,7 +33,7 @@ func TestNetworkCreateConnectionError(t *testing.T) {
|
| 33 | 33 |
client, err := NewClientWithOpts(WithAPIVersionNegotiation(), WithHost("tcp://no-such-host.invalid"))
|
| 34 | 34 |
assert.NilError(t, err) |
| 35 | 35 |
|
| 36 |
- _, err = client.NetworkCreate(context.Background(), "mynetwork", network.CreateOptions{})
|
|
| 36 |
+ _, err = client.NetworkCreate(context.Background(), "mynetwork", NetworkCreateOptions{})
|
|
| 37 | 37 |
assert.Check(t, is.ErrorType(err, IsErrConnectionFailed)) |
| 38 | 38 |
} |
| 39 | 39 |
|
| ... | ... |
@@ -65,7 +65,7 @@ func TestNetworkCreate(t *testing.T) {
|
| 65 | 65 |
} |
| 66 | 66 |
|
| 67 | 67 |
enableIPv6 := true |
| 68 |
- networkResponse, err := client.NetworkCreate(context.Background(), "mynetwork", network.CreateOptions{
|
|
| 68 |
+ networkResponse, err := client.NetworkCreate(context.Background(), "mynetwork", NetworkCreateOptions{
|
|
| 69 | 69 |
Driver: "mydriver", |
| 70 | 70 |
EnableIPv6: &enableIPv6, |
| 71 | 71 |
Internal: true, |
| ... | ... |
@@ -628,34 +628,35 @@ func (c *containerConfig) serviceConfig() *clustertypes.ServiceConfig {
|
| 628 | 628 |
func networkCreateRequest(name string, nw *api.Network) clustertypes.NetworkCreateRequest {
|
| 629 | 629 |
ipv4Enabled := true |
| 630 | 630 |
ipv6Enabled := nw.Spec.Ipv6Enabled |
| 631 |
- options := network.CreateOptions{
|
|
| 632 |
- // ID: nw.ID, |
|
| 633 |
- Labels: nw.Spec.Annotations.Labels, |
|
| 631 |
+ req := network.CreateRequest{
|
|
| 632 |
+ Name: name, // TODO(thaJeztah): this is the same as [nw.Spec.Annotations.Name]; consider using that instead |
|
| 633 |
+ Scope: scope.Swarm, |
|
| 634 |
+ EnableIPv4: &ipv4Enabled, |
|
| 635 |
+ EnableIPv6: &ipv6Enabled, |
|
| 634 | 636 |
Internal: nw.Spec.Internal, |
| 635 | 637 |
Attachable: nw.Spec.Attachable, |
| 636 | 638 |
Ingress: convert.IsIngressNetwork(nw), |
| 637 |
- EnableIPv4: &ipv4Enabled, |
|
| 638 |
- EnableIPv6: &ipv6Enabled, |
|
| 639 |
- Scope: scope.Swarm, |
|
| 639 |
+ Labels: nw.Spec.Annotations.Labels, |
|
| 640 | 640 |
} |
| 641 | 641 |
|
| 642 | 642 |
if nw.Spec.GetNetwork() != "" {
|
| 643 |
- options.ConfigFrom = &network.ConfigReference{
|
|
| 643 |
+ req.ConfigFrom = &network.ConfigReference{
|
|
| 644 | 644 |
Network: nw.Spec.GetNetwork(), |
| 645 | 645 |
} |
| 646 | 646 |
} |
| 647 | 647 |
|
| 648 | 648 |
if nw.DriverState != nil {
|
| 649 |
- options.Driver = nw.DriverState.Name |
|
| 650 |
- options.Options = nw.DriverState.Options |
|
| 649 |
+ req.Driver = nw.DriverState.Name |
|
| 650 |
+ req.Options = nw.DriverState.Options |
|
| 651 | 651 |
} |
| 652 |
+ |
|
| 652 | 653 |
if nw.IPAM != nil {
|
| 653 |
- options.IPAM = &network.IPAM{
|
|
| 654 |
+ req.IPAM = &network.IPAM{
|
|
| 654 | 655 |
Driver: nw.IPAM.Driver.Name, |
| 655 | 656 |
Options: nw.IPAM.Driver.Options, |
| 656 | 657 |
} |
| 657 | 658 |
for _, ic := range nw.IPAM.Configs {
|
| 658 |
- options.IPAM.Config = append(options.IPAM.Config, network.IPAMConfig{
|
|
| 659 |
+ req.IPAM.Config = append(req.IPAM.Config, network.IPAMConfig{
|
|
| 659 | 660 |
Subnet: ic.Subnet, |
| 660 | 661 |
IPRange: ic.Range, |
| 661 | 662 |
Gateway: ic.Gateway, |
| ... | ... |
@@ -664,11 +665,8 @@ func networkCreateRequest(name string, nw *api.Network) clustertypes.NetworkCrea |
| 664 | 664 |
} |
| 665 | 665 |
|
| 666 | 666 |
return clustertypes.NetworkCreateRequest{
|
| 667 |
- ID: nw.ID, |
|
| 668 |
- CreateRequest: network.CreateRequest{
|
|
| 669 |
- Name: name, // TODO(thaJeztah): this is the same as [nw.Spec.Annotations.Name]; consider using that instead |
|
| 670 |
- CreateOptions: options, |
|
| 671 |
- }, |
|
| 667 |
+ ID: nw.ID, |
|
| 668 |
+ CreateRequest: req, |
|
| 672 | 669 |
} |
| 673 | 670 |
} |
| 674 | 671 |
|
| ... | ... |
@@ -214,13 +214,14 @@ func (e *executor) Configure(ctx context.Context, node *api.Node) error {
|
| 214 | 214 |
if ingressNA == nil {
|
| 215 | 215 |
e.backend.ReleaseIngress() |
| 216 | 216 |
} else {
|
| 217 |
- options := network.CreateOptions{
|
|
| 217 |
+ networkCreateRequest := network.CreateRequest{
|
|
| 218 |
+ Name: ingressNA.Network.Spec.Annotations.Name, |
|
| 218 | 219 |
Driver: ingressNA.Network.DriverState.Name, |
| 219 | 220 |
IPAM: &network.IPAM{
|
| 220 | 221 |
Driver: ingressNA.Network.IPAM.Driver.Name, |
| 221 | 222 |
}, |
| 222 |
- Options: ingressNA.Network.DriverState.Options, |
|
| 223 | 223 |
Ingress: true, |
| 224 |
+ Options: ingressNA.Network.DriverState.Options, |
|
| 224 | 225 |
} |
| 225 | 226 |
|
| 226 | 227 |
for _, ic := range ingressNA.Network.IPAM.Configs {
|
| ... | ... |
@@ -229,15 +230,12 @@ func (e *executor) Configure(ctx context.Context, node *api.Node) error {
|
| 229 | 229 |
IPRange: ic.Range, |
| 230 | 230 |
Gateway: ic.Gateway, |
| 231 | 231 |
} |
| 232 |
- options.IPAM.Config = append(options.IPAM.Config, c) |
|
| 232 |
+ networkCreateRequest.IPAM.Config = append(networkCreateRequest.IPAM.Config, c) |
|
| 233 | 233 |
} |
| 234 | 234 |
|
| 235 | 235 |
_, err := e.backend.SetupIngress(clustertypes.NetworkCreateRequest{
|
| 236 |
- ID: ingressNA.Network.ID, |
|
| 237 |
- CreateRequest: network.CreateRequest{
|
|
| 238 |
- Name: ingressNA.Network.Spec.Annotations.Name, |
|
| 239 |
- CreateOptions: options, |
|
| 240 |
- }, |
|
| 236 |
+ ID: ingressNA.Network.ID, |
|
| 237 |
+ CreateRequest: networkCreateRequest, |
|
| 241 | 238 |
}, ingressNA.Addresses[0]) |
| 242 | 239 |
if err != nil {
|
| 243 | 240 |
return err |
| ... | ... |
@@ -67,12 +67,10 @@ func (s *DockerAPISuite) TestAPINetworkInspectUserDefinedNetwork(c *testing.T) {
|
| 67 | 67 |
Config: []network.IPAMConfig{{Subnet: "172.28.0.0/16", IPRange: "172.28.5.0/24", Gateway: "172.28.5.254"}},
|
| 68 | 68 |
} |
| 69 | 69 |
config := network.CreateRequest{
|
| 70 |
- Name: "br0", |
|
| 71 |
- CreateOptions: network.CreateOptions{
|
|
| 72 |
- Driver: "bridge", |
|
| 73 |
- IPAM: ipam, |
|
| 74 |
- Options: map[string]string{"foo": "bar", "opts": "dopts"},
|
|
| 75 |
- }, |
|
| 70 |
+ Name: "br0", |
|
| 71 |
+ Driver: "bridge", |
|
| 72 |
+ IPAM: ipam, |
|
| 73 |
+ Options: map[string]string{"foo": "bar", "opts": "dopts"},
|
|
| 76 | 74 |
} |
| 77 | 75 |
id0 := createNetwork(c, config, http.StatusCreated) |
| 78 | 76 |
assert.Assert(c, isNetworkAvailable(c, "br0")) |
| ... | ... |
@@ -140,11 +138,9 @@ func (s *DockerAPISuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *testing.T) |
| 140 | 140 |
Config: []network.IPAMConfig{{Subnet: "192.178.0.0/16", IPRange: "192.178.128.0/17", Gateway: "192.178.138.100"}},
|
| 141 | 141 |
} |
| 142 | 142 |
config0 := network.CreateRequest{
|
| 143 |
- Name: "test0", |
|
| 144 |
- CreateOptions: network.CreateOptions{
|
|
| 145 |
- Driver: "bridge", |
|
| 146 |
- IPAM: ipam0, |
|
| 147 |
- }, |
|
| 143 |
+ Name: "test0", |
|
| 144 |
+ Driver: "bridge", |
|
| 145 |
+ IPAM: ipam0, |
|
| 148 | 146 |
} |
| 149 | 147 |
id0 := createNetwork(c, config0, http.StatusCreated) |
| 150 | 148 |
assert.Assert(c, isNetworkAvailable(c, "test0")) |
| ... | ... |
@@ -155,11 +151,9 @@ func (s *DockerAPISuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *testing.T) |
| 155 | 155 |
} |
| 156 | 156 |
// test1 bridge network overlaps with test0 |
| 157 | 157 |
config1 := network.CreateRequest{
|
| 158 |
- Name: "test1", |
|
| 159 |
- CreateOptions: network.CreateOptions{
|
|
| 160 |
- Driver: "bridge", |
|
| 161 |
- IPAM: ipam1, |
|
| 162 |
- }, |
|
| 158 |
+ Name: "test1", |
|
| 159 |
+ Driver: "bridge", |
|
| 160 |
+ IPAM: ipam1, |
|
| 163 | 161 |
} |
| 164 | 162 |
createNetwork(c, config1, http.StatusForbidden) |
| 165 | 163 |
assert.Assert(c, !isNetworkAvailable(c, "test1")) |
| ... | ... |
@@ -170,11 +164,9 @@ func (s *DockerAPISuite) TestAPINetworkIPAMMultipleBridgeNetworks(c *testing.T) |
| 170 | 170 |
} |
| 171 | 171 |
// test2 bridge network does not overlap |
| 172 | 172 |
config2 := network.CreateRequest{
|
| 173 |
- Name: "test2", |
|
| 174 |
- CreateOptions: network.CreateOptions{
|
|
| 175 |
- Driver: "bridge", |
|
| 176 |
- IPAM: ipam2, |
|
| 177 |
- }, |
|
| 173 |
+ Name: "test2", |
|
| 174 |
+ Driver: "bridge", |
|
| 175 |
+ IPAM: ipam2, |
|
| 178 | 176 |
} |
| 179 | 177 |
createNetwork(c, config2, http.StatusCreated) |
| 180 | 178 |
assert.Assert(c, isNetworkAvailable(c, "test2")) |
| ... | ... |
@@ -20,7 +20,6 @@ import ( |
| 20 | 20 |
"github.com/cloudflare/cfssl/initca" |
| 21 | 21 |
cerrdefs "github.com/containerd/errdefs" |
| 22 | 22 |
"github.com/moby/moby/api/types/container" |
| 23 |
- "github.com/moby/moby/api/types/network" |
|
| 24 | 23 |
"github.com/moby/moby/api/types/swarm" |
| 25 | 24 |
"github.com/moby/moby/client" |
| 26 | 25 |
"github.com/moby/moby/v2/integration-cli/checker" |
| ... | ... |
@@ -1023,7 +1022,7 @@ func (s *DockerSwarmSuite) TestAPINetworkInspectWithScope(c *testing.T) {
|
| 1023 | 1023 |
name := "test-scoped-network" |
| 1024 | 1024 |
apiclient := d.NewClientT(c) |
| 1025 | 1025 |
|
| 1026 |
- resp, err := apiclient.NetworkCreate(ctx, name, network.CreateOptions{Driver: "overlay"})
|
|
| 1026 |
+ resp, err := apiclient.NetworkCreate(ctx, name, client.NetworkCreateOptions{Driver: "overlay"})
|
|
| 1027 | 1027 |
assert.NilError(c, err) |
| 1028 | 1028 |
|
| 1029 | 1029 |
nw, err := apiclient.NetworkInspect(ctx, name, client.NetworkInspectOptions{})
|
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
|
| 6 | 6 |
containertypes "github.com/moby/moby/api/types/container" |
| 7 | 7 |
"github.com/moby/moby/api/types/network" |
| 8 |
+ "github.com/moby/moby/client" |
|
| 8 | 9 |
"github.com/moby/moby/v2/integration/internal/container" |
| 9 | 10 |
"gotest.tools/v3/assert" |
| 10 | 11 |
is "gotest.tools/v3/assert/cmp" |
| ... | ... |
@@ -113,7 +114,7 @@ func TestRenameAnonymousContainer(t *testing.T) {
|
| 113 | 113 |
apiClient := testEnv.APIClient() |
| 114 | 114 |
|
| 115 | 115 |
networkName := "network1" + t.Name() |
| 116 |
- _, err := apiClient.NetworkCreate(ctx, networkName, network.CreateOptions{})
|
|
| 116 |
+ _, err := apiClient.NetworkCreate(ctx, networkName, client.NetworkCreateOptions{})
|
|
| 117 | 117 |
|
| 118 | 118 |
assert.NilError(t, err) |
| 119 | 119 |
cID := container.Run(ctx, t, apiClient, func(c *container.TestContainerConfig) {
|
| ... | ... |
@@ -4,32 +4,31 @@ import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"testing" |
| 6 | 6 |
|
| 7 |
- "github.com/moby/moby/api/types/network" |
|
| 8 | 7 |
"github.com/moby/moby/client" |
| 9 | 8 |
"gotest.tools/v3/assert" |
| 10 | 9 |
) |
| 11 | 10 |
|
| 12 |
-func createNetwork(ctx context.Context, client client.APIClient, name string, ops ...func(*network.CreateOptions)) (string, error) {
|
|
| 13 |
- config := network.CreateOptions{}
|
|
| 11 |
+func createNetwork(ctx context.Context, apiClient client.APIClient, name string, ops ...func(*client.NetworkCreateOptions)) (string, error) {
|
|
| 12 |
+ config := client.NetworkCreateOptions{}
|
|
| 14 | 13 |
|
| 15 | 14 |
for _, op := range ops {
|
| 16 | 15 |
op(&config) |
| 17 | 16 |
} |
| 18 | 17 |
|
| 19 |
- n, err := client.NetworkCreate(ctx, name, config) |
|
| 18 |
+ n, err := apiClient.NetworkCreate(ctx, name, config) |
|
| 20 | 19 |
return n.ID, err |
| 21 | 20 |
} |
| 22 | 21 |
|
| 23 | 22 |
// Create creates a network with the specified options |
| 24 |
-func Create(ctx context.Context, client client.APIClient, name string, ops ...func(*network.CreateOptions)) (string, error) {
|
|
| 25 |
- return createNetwork(ctx, client, name, ops...) |
|
| 23 |
+func Create(ctx context.Context, apiClient client.APIClient, name string, ops ...func(*client.NetworkCreateOptions)) (string, error) {
|
|
| 24 |
+ return createNetwork(ctx, apiClient, name, ops...) |
|
| 26 | 25 |
} |
| 27 | 26 |
|
| 28 | 27 |
// CreateNoError creates a network with the specified options and verifies there were no errors |
| 29 |
-func CreateNoError(ctx context.Context, t *testing.T, client client.APIClient, name string, ops ...func(*network.CreateOptions)) string {
|
|
| 28 |
+func CreateNoError(ctx context.Context, t *testing.T, apiClient client.APIClient, name string, ops ...func(*client.NetworkCreateOptions)) string {
|
|
| 30 | 29 |
t.Helper() |
| 31 | 30 |
|
| 32 |
- name, err := createNetwork(ctx, client, name, ops...) |
|
| 31 |
+ name, err := createNetwork(ctx, apiClient, name, ops...) |
|
| 33 | 32 |
assert.NilError(t, err) |
| 34 | 33 |
return name |
| 35 | 34 |
} |
| ... | ... |
@@ -2,85 +2,86 @@ package network |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"github.com/moby/moby/api/types/network" |
| 5 |
+ "github.com/moby/moby/client" |
|
| 5 | 6 |
) |
| 6 | 7 |
|
| 7 | 8 |
// WithDriver sets the driver of the network |
| 8 |
-func WithDriver(driver string) func(*network.CreateOptions) {
|
|
| 9 |
- return func(n *network.CreateOptions) {
|
|
| 9 |
+func WithDriver(driver string) func(*client.NetworkCreateOptions) {
|
|
| 10 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 10 | 11 |
n.Driver = driver |
| 11 | 12 |
} |
| 12 | 13 |
} |
| 13 | 14 |
|
| 14 | 15 |
// WithIPv4 enables/disables IPv4 on the network |
| 15 |
-func WithIPv4(enable bool) func(*network.CreateOptions) {
|
|
| 16 |
- return func(n *network.CreateOptions) {
|
|
| 16 |
+func WithIPv4(enable bool) func(*client.NetworkCreateOptions) {
|
|
| 17 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 17 | 18 |
enableIPv4 := enable |
| 18 | 19 |
n.EnableIPv4 = &enableIPv4 |
| 19 | 20 |
} |
| 20 | 21 |
} |
| 21 | 22 |
|
| 22 | 23 |
// WithIPv6 Enables IPv6 on the network |
| 23 |
-func WithIPv6() func(*network.CreateOptions) {
|
|
| 24 |
- return func(n *network.CreateOptions) {
|
|
| 24 |
+func WithIPv6() func(*client.NetworkCreateOptions) {
|
|
| 25 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 25 | 26 |
enableIPv6 := true |
| 26 | 27 |
n.EnableIPv6 = &enableIPv6 |
| 27 | 28 |
} |
| 28 | 29 |
} |
| 29 | 30 |
|
| 30 | 31 |
// WithIPv4Disabled makes sure IPv4 is disabled on the network. |
| 31 |
-func WithIPv4Disabled() func(*network.CreateOptions) {
|
|
| 32 |
- return func(n *network.CreateOptions) {
|
|
| 32 |
+func WithIPv4Disabled() func(*client.NetworkCreateOptions) {
|
|
| 33 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 33 | 34 |
enable := false |
| 34 | 35 |
n.EnableIPv4 = &enable |
| 35 | 36 |
} |
| 36 | 37 |
} |
| 37 | 38 |
|
| 38 | 39 |
// WithIPv6Disabled makes sure IPv6 is disabled on the network. |
| 39 |
-func WithIPv6Disabled() func(*network.CreateOptions) {
|
|
| 40 |
- return func(n *network.CreateOptions) {
|
|
| 40 |
+func WithIPv6Disabled() func(*client.NetworkCreateOptions) {
|
|
| 41 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 41 | 42 |
enable := false |
| 42 | 43 |
n.EnableIPv6 = &enable |
| 43 | 44 |
} |
| 44 | 45 |
} |
| 45 | 46 |
|
| 46 | 47 |
// WithInternal enables Internal flag on the create network request |
| 47 |
-func WithInternal() func(*network.CreateOptions) {
|
|
| 48 |
- return func(n *network.CreateOptions) {
|
|
| 48 |
+func WithInternal() func(*client.NetworkCreateOptions) {
|
|
| 49 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 49 | 50 |
n.Internal = true |
| 50 | 51 |
} |
| 51 | 52 |
} |
| 52 | 53 |
|
| 53 | 54 |
// WithConfigOnly sets the ConfigOnly flag in the create network request |
| 54 |
-func WithConfigOnly(co bool) func(*network.CreateOptions) {
|
|
| 55 |
- return func(n *network.CreateOptions) {
|
|
| 55 |
+func WithConfigOnly(co bool) func(*client.NetworkCreateOptions) {
|
|
| 56 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 56 | 57 |
n.ConfigOnly = co |
| 57 | 58 |
} |
| 58 | 59 |
} |
| 59 | 60 |
|
| 60 | 61 |
// WithConfigFrom sets the ConfigOnly flag in the create network request |
| 61 |
-func WithConfigFrom(name string) func(*network.CreateOptions) {
|
|
| 62 |
- return func(n *network.CreateOptions) {
|
|
| 62 |
+func WithConfigFrom(name string) func(*client.NetworkCreateOptions) {
|
|
| 63 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 63 | 64 |
n.ConfigFrom = &network.ConfigReference{Network: name}
|
| 64 | 65 |
} |
| 65 | 66 |
} |
| 66 | 67 |
|
| 67 | 68 |
// WithAttachable sets Attachable flag on the create network request |
| 68 |
-func WithAttachable() func(*network.CreateOptions) {
|
|
| 69 |
- return func(n *network.CreateOptions) {
|
|
| 69 |
+func WithAttachable() func(*client.NetworkCreateOptions) {
|
|
| 70 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 70 | 71 |
n.Attachable = true |
| 71 | 72 |
} |
| 72 | 73 |
} |
| 73 | 74 |
|
| 74 | 75 |
// WithScope sets the network scope. |
| 75 |
-func WithScope(s string) func(*network.CreateOptions) {
|
|
| 76 |
- return func(n *network.CreateOptions) {
|
|
| 76 |
+func WithScope(s string) func(*client.NetworkCreateOptions) {
|
|
| 77 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 77 | 78 |
n.Scope = s |
| 78 | 79 |
} |
| 79 | 80 |
} |
| 80 | 81 |
|
| 81 | 82 |
// WithMacvlan sets the network as macvlan with the specified parent |
| 82 |
-func WithMacvlan(parent string) func(*network.CreateOptions) {
|
|
| 83 |
- return func(n *network.CreateOptions) {
|
|
| 83 |
+func WithMacvlan(parent string) func(*client.NetworkCreateOptions) {
|
|
| 84 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 84 | 85 |
n.Driver = "macvlan" |
| 85 | 86 |
if parent != "" {
|
| 86 | 87 |
n.Options = map[string]string{
|
| ... | ... |
@@ -91,8 +92,8 @@ func WithMacvlan(parent string) func(*network.CreateOptions) {
|
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 | 93 |
// WithMacvlanPassthru sets the network as macvlan with the specified parent in passthru mode |
| 94 |
-func WithMacvlanPassthru(parent string) func(options *network.CreateOptions) {
|
|
| 95 |
- return func(n *network.CreateOptions) {
|
|
| 94 |
+func WithMacvlanPassthru(parent string) func(options *client.NetworkCreateOptions) {
|
|
| 95 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 96 | 96 |
n.Driver = "macvlan" |
| 97 | 97 |
n.Options = map[string]string{
|
| 98 | 98 |
"macvlan_mode": "passthru", |
| ... | ... |
@@ -104,8 +105,8 @@ func WithMacvlanPassthru(parent string) func(options *network.CreateOptions) {
|
| 104 | 104 |
} |
| 105 | 105 |
|
| 106 | 106 |
// WithIPvlan sets the network as ipvlan with the specified parent and mode |
| 107 |
-func WithIPvlan(parent, mode string) func(*network.CreateOptions) {
|
|
| 108 |
- return func(n *network.CreateOptions) {
|
|
| 107 |
+func WithIPvlan(parent, mode string) func(*client.NetworkCreateOptions) {
|
|
| 108 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 109 | 109 |
n.Driver = "ipvlan" |
| 110 | 110 |
if n.Options == nil {
|
| 111 | 111 |
n.Options = map[string]string{}
|
| ... | ... |
@@ -120,8 +121,8 @@ func WithIPvlan(parent, mode string) func(*network.CreateOptions) {
|
| 120 | 120 |
} |
| 121 | 121 |
|
| 122 | 122 |
// WithOption adds the specified key/value pair to network's options |
| 123 |
-func WithOption(key, value string) func(*network.CreateOptions) {
|
|
| 124 |
- return func(n *network.CreateOptions) {
|
|
| 123 |
+func WithOption(key, value string) func(*client.NetworkCreateOptions) {
|
|
| 124 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 125 | 125 |
if n.Options == nil {
|
| 126 | 126 |
n.Options = map[string]string{}
|
| 127 | 127 |
} |
| ... | ... |
@@ -130,13 +131,13 @@ func WithOption(key, value string) func(*network.CreateOptions) {
|
| 130 | 130 |
} |
| 131 | 131 |
|
| 132 | 132 |
// WithIPAM adds an IPAM with the specified Subnet and Gateway to the network |
| 133 |
-func WithIPAM(subnet, gateway string) func(*network.CreateOptions) {
|
|
| 133 |
+func WithIPAM(subnet, gateway string) func(*client.NetworkCreateOptions) {
|
|
| 134 | 134 |
return WithIPAMRange(subnet, "", gateway) |
| 135 | 135 |
} |
| 136 | 136 |
|
| 137 | 137 |
// WithIPAMRange adds an IPAM with the specified Subnet, IPRange and Gateway to the network |
| 138 |
-func WithIPAMRange(subnet, iprange, gateway string) func(*network.CreateOptions) {
|
|
| 139 |
- return func(n *network.CreateOptions) {
|
|
| 138 |
+func WithIPAMRange(subnet, iprange, gateway string) func(*client.NetworkCreateOptions) {
|
|
| 139 |
+ return func(n *client.NetworkCreateOptions) {
|
|
| 140 | 140 |
if n.IPAM == nil {
|
| 141 | 141 |
n.IPAM = &network.IPAM{}
|
| 142 | 142 |
} |
| ... | ... |
@@ -127,7 +127,7 @@ func TestDefaultIPvOptOverride(t *testing.T) {
|
| 127 | 127 |
t.Run(fmt.Sprintf("override4=%v,override6=%v", override4, override6), func(t *testing.T) {
|
| 128 | 128 |
t.Parallel() |
| 129 | 129 |
netName := fmt.Sprintf("tdioo-%v-%v", override4, override6)
|
| 130 |
- var nopts []func(*networktypes.CreateOptions) |
|
| 130 |
+ var nopts []func(*client.NetworkCreateOptions) |
|
| 131 | 131 |
if override4 {
|
| 132 | 132 |
nopts = append(nopts, network.WithIPv4(true)) |
| 133 | 133 |
} |
| ... | ... |
@@ -373,7 +373,7 @@ func TestPointToPoint(t *testing.T) {
|
| 373 | 373 |
|
| 374 | 374 |
testcases := []struct {
|
| 375 | 375 |
name string |
| 376 |
- netOpt func(*networktypes.CreateOptions) |
|
| 376 |
+ netOpt func(*client.NetworkCreateOptions) |
|
| 377 | 377 |
}{
|
| 378 | 378 |
{
|
| 379 | 379 |
name: "inhibit_ipv4", |
| ... | ... |
@@ -31,7 +31,6 @@ import ( |
| 31 | 31 |
"time" |
| 32 | 32 |
|
| 33 | 33 |
containertypes "github.com/moby/moby/api/types/container" |
| 34 |
- networktypes "github.com/moby/moby/api/types/network" |
|
| 35 | 34 |
swarmtypes "github.com/moby/moby/api/types/swarm" |
| 36 | 35 |
"github.com/moby/moby/client" |
| 37 | 36 |
"github.com/moby/moby/v2/daemon/libnetwork/drivers/bridge" |
| ... | ... |
@@ -311,7 +310,7 @@ func createBridgeNetworks(ctx context.Context, t *testing.T, d *daemon.Daemon, s |
| 311 | 311 |
if gwMode == "" {
|
| 312 | 312 |
gwMode = "nat" |
| 313 | 313 |
} |
| 314 |
- netOpts := []func(*networktypes.CreateOptions){
|
|
| 314 |
+ netOpts := []func(*client.NetworkCreateOptions){
|
|
| 315 | 315 |
network.WithIPAM(docNetworks[i], docGateways[i]), |
| 316 | 316 |
network.WithOption(bridge.BridgeName, nw.name), |
| 317 | 317 |
network.WithOption(bridge.IPv4GatewayMode, gwMode), |
| ... | ... |
@@ -29,8 +29,8 @@ import ( |
| 29 | 29 |
"text/template" |
| 30 | 30 |
|
| 31 | 31 |
containertypes "github.com/moby/moby/api/types/container" |
| 32 |
- networktypes "github.com/moby/moby/api/types/network" |
|
| 33 | 32 |
swarmtypes "github.com/moby/moby/api/types/swarm" |
| 33 |
+ "github.com/moby/moby/client" |
|
| 34 | 34 |
"github.com/moby/moby/v2/daemon/libnetwork/drivers/bridge" |
| 35 | 35 |
"github.com/moby/moby/v2/integration/internal/container" |
| 36 | 36 |
"github.com/moby/moby/v2/integration/internal/network" |
| ... | ... |
@@ -283,7 +283,7 @@ func createBridgeNetworks(ctx context.Context, t *testing.T, d *daemon.Daemon, s |
| 283 | 283 |
if gwMode == "" {
|
| 284 | 284 |
gwMode = "nat" |
| 285 | 285 |
} |
| 286 |
- netOpts := []func(*networktypes.CreateOptions){
|
|
| 286 |
+ netOpts := []func(*client.NetworkCreateOptions){
|
|
| 287 | 287 |
network.WithIPAM(docNetworks[i], docGateways[i]), |
| 288 | 288 |
network.WithOption(bridge.BridgeName, nw.name), |
| 289 | 289 |
network.WithOption(bridge.IPv4GatewayMode, gwMode), |
| ... | ... |
@@ -490,7 +490,7 @@ func TestIpvlanIPAM(t *testing.T) {
|
| 490 | 490 |
ctx := testutil.StartSpan(ctx, t) |
| 491 | 491 |
c := d.NewClientT(t, dclient.WithVersion(tc.apiVersion)) |
| 492 | 492 |
|
| 493 |
- netOpts := []func(*network.CreateOptions){
|
|
| 493 |
+ netOpts := []func(*dclient.NetworkCreateOptions){
|
|
| 494 | 494 |
net.WithIPvlan("", "l3"),
|
| 495 | 495 |
net.WithIPv4(tc.enableIPv4), |
| 496 | 496 |
} |
| ... | ... |
@@ -591,7 +591,7 @@ func TestIPVlanDNS(t *testing.T) {
|
| 591 | 591 |
name := fmt.Sprintf("Mode=%v/HasParent=%v/Internal=%v", mode, tc.parent != "", tc.internal)
|
| 592 | 592 |
t.Run(name, func(t *testing.T) {
|
| 593 | 593 |
ctx := testutil.StartSpan(ctx, t) |
| 594 |
- createOpts := []func(*network.CreateOptions){
|
|
| 594 |
+ createOpts := []func(*dclient.NetworkCreateOptions){
|
|
| 595 | 595 |
net.WithIPvlan(tc.parent, mode), |
| 596 | 596 |
} |
| 597 | 597 |
if tc.internal {
|
| ... | ... |
@@ -487,7 +487,7 @@ func TestMacvlanIPAM(t *testing.T) {
|
| 487 | 487 |
ctx := testutil.StartSpan(ctx, t) |
| 488 | 488 |
c := d.NewClientT(t, client.WithVersion(tc.apiVersion)) |
| 489 | 489 |
|
| 490 |
- netOpts := []func(*network.CreateOptions){
|
|
| 490 |
+ netOpts := []func(*client.NetworkCreateOptions){
|
|
| 491 | 491 |
net.WithMacvlan(""),
|
| 492 | 492 |
net.WithOption("macvlan_mode", "bridge"),
|
| 493 | 493 |
net.WithIPv4(tc.enableIPv4), |
| ... | ... |
@@ -587,7 +587,7 @@ func TestMACVlanDNS(t *testing.T) {
|
| 587 | 587 |
for _, tc := range testcases {
|
| 588 | 588 |
t.Run(tc.name, func(t *testing.T) {
|
| 589 | 589 |
ctx := testutil.StartSpan(ctx, t) |
| 590 |
- createOpts := []func(*network.CreateOptions){
|
|
| 590 |
+ createOpts := []func(*client.NetworkCreateOptions){
|
|
| 591 | 591 |
net.WithMacvlan(tc.parent), |
| 592 | 592 |
} |
| 593 | 593 |
if tc.internal {
|
| ... | ... |
@@ -143,7 +143,7 @@ func TestDefaultNetworkOpts(t *testing.T) {
|
| 143 | 143 |
|
| 144 | 144 |
if tc.configFrom {
|
| 145 | 145 |
// Create a new network config |
| 146 |
- network.CreateNoError(ctx, t, c, "from-net", func(create *networktypes.CreateOptions) {
|
|
| 146 |
+ network.CreateNoError(ctx, t, c, "from-net", func(create *client.NetworkCreateOptions) {
|
|
| 147 | 147 |
create.ConfigOnly = true |
| 148 | 148 |
create.Options = map[string]string{
|
| 149 | 149 |
"com.docker.network.driver.mtu": fmt.Sprint(tc.mtu), |
| ... | ... |
@@ -154,7 +154,7 @@ func TestDefaultNetworkOpts(t *testing.T) {
|
| 154 | 154 |
|
| 155 | 155 |
// Create a new network |
| 156 | 156 |
networkName := "testnet" |
| 157 |
- networkId := network.CreateNoError(ctx, t, c, networkName, func(create *networktypes.CreateOptions) {
|
|
| 157 |
+ networkId := network.CreateNoError(ctx, t, c, networkName, func(create *client.NetworkCreateOptions) {
|
|
| 158 | 158 |
if tc.configFrom {
|
| 159 | 159 |
create.ConfigFrom = &networktypes.ConfigReference{
|
| 160 | 160 |
Network: "from-net", |
| ... | ... |
@@ -196,7 +196,7 @@ func TestForbidDuplicateNetworkNames(t *testing.T) {
|
| 196 | 196 |
network.CreateNoError(ctx, t, c, "testnet") |
| 197 | 197 |
defer network.RemoveNoError(ctx, t, c, "testnet") |
| 198 | 198 |
|
| 199 |
- _, err := c.NetworkCreate(ctx, "testnet", networktypes.CreateOptions{})
|
|
| 199 |
+ _, err := c.NetworkCreate(ctx, "testnet", client.NetworkCreateOptions{})
|
|
| 200 | 200 |
assert.Error(t, err, "Error response from daemon: network with name testnet already exists", "2nd NetworkCreate call should have failed") |
| 201 | 201 |
} |
| 202 | 202 |
|
| ... | ... |
@@ -49,7 +49,7 @@ func TestBridgeICC(t *testing.T) {
|
| 49 | 49 |
|
| 50 | 50 |
testcases := []struct {
|
| 51 | 51 |
name string |
| 52 |
- bridgeOpts []func(*networktypes.CreateOptions) |
|
| 52 |
+ bridgeOpts []func(*client.NetworkCreateOptions) |
|
| 53 | 53 |
ctr1MacAddress string |
| 54 | 54 |
isIPv6 bool |
| 55 | 55 |
isLinkLocal bool |
| ... | ... |
@@ -57,17 +57,17 @@ func TestBridgeICC(t *testing.T) {
|
| 57 | 57 |
}{
|
| 58 | 58 |
{
|
| 59 | 59 |
name: "IPv4 non-internal network", |
| 60 |
- bridgeOpts: []func(*networktypes.CreateOptions){},
|
|
| 60 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){},
|
|
| 61 | 61 |
}, |
| 62 | 62 |
{
|
| 63 | 63 |
name: "IPv4 internal network", |
| 64 |
- bridgeOpts: []func(*networktypes.CreateOptions){
|
|
| 64 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){
|
|
| 65 | 65 |
network.WithInternal(), |
| 66 | 66 |
}, |
| 67 | 67 |
}, |
| 68 | 68 |
{
|
| 69 | 69 |
name: "IPv6 ULA on non-internal network", |
| 70 |
- bridgeOpts: []func(*networktypes.CreateOptions){
|
|
| 70 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){
|
|
| 71 | 71 |
network.WithIPv6(), |
| 72 | 72 |
network.WithIPAM("fdf1:a844:380c:b200::/64", "fdf1:a844:380c:b200::1"),
|
| 73 | 73 |
}, |
| ... | ... |
@@ -75,7 +75,7 @@ func TestBridgeICC(t *testing.T) {
|
| 75 | 75 |
}, |
| 76 | 76 |
{
|
| 77 | 77 |
name: "IPv6 ULA on internal network", |
| 78 |
- bridgeOpts: []func(*networktypes.CreateOptions){
|
|
| 78 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){
|
|
| 79 | 79 |
network.WithIPv6(), |
| 80 | 80 |
network.WithInternal(), |
| 81 | 81 |
network.WithIPAM("fdf1:a844:380c:b247::/64", "fdf1:a844:380c:b247::1"),
|
| ... | ... |
@@ -84,7 +84,7 @@ func TestBridgeICC(t *testing.T) {
|
| 84 | 84 |
}, |
| 85 | 85 |
{
|
| 86 | 86 |
name: "IPv6 link-local address on non-internal network", |
| 87 |
- bridgeOpts: []func(*networktypes.CreateOptions){
|
|
| 87 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){
|
|
| 88 | 88 |
network.WithIPv6(), |
| 89 | 89 |
// There's no real way to specify an IPv6 network is only used with SLAAC link-local IPv6 addresses. |
| 90 | 90 |
// What we can do instead, is to tell the IPAM driver to assign addresses from the link-local prefix. |
| ... | ... |
@@ -97,7 +97,7 @@ func TestBridgeICC(t *testing.T) {
|
| 97 | 97 |
}, |
| 98 | 98 |
{
|
| 99 | 99 |
name: "IPv6 link-local address on internal network", |
| 100 |
- bridgeOpts: []func(*networktypes.CreateOptions){
|
|
| 100 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){
|
|
| 101 | 101 |
network.WithIPv6(), |
| 102 | 102 |
network.WithInternal(), |
| 103 | 103 |
// See the note above about link-local addresses. |
| ... | ... |
@@ -115,7 +115,7 @@ func TestBridgeICC(t *testing.T) {
|
| 115 | 115 |
// addresses need not be qualified with a zone index." |
| 116 | 116 |
// So, for this common case, LL addresses should be included in DNS config. |
| 117 | 117 |
name: "IPv6 link-local address on non-internal network ping by name", |
| 118 |
- bridgeOpts: []func(*networktypes.CreateOptions){
|
|
| 118 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){
|
|
| 119 | 119 |
network.WithIPv6(), |
| 120 | 120 |
network.WithIPAM("fe80::/64", "fe80::1"),
|
| 121 | 121 |
}, |
| ... | ... |
@@ -128,7 +128,7 @@ func TestBridgeICC(t *testing.T) {
|
| 128 | 128 |
// configure two networks with the same LL subnet, although perhaps it should |
| 129 | 129 |
// be). So, again, no zone index is required and the LL address should be |
| 130 | 130 |
// included in DNS config. |
| 131 |
- bridgeOpts: []func(*networktypes.CreateOptions){
|
|
| 131 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){
|
|
| 132 | 132 |
network.WithIPv6(), |
| 133 | 133 |
network.WithIPAM("fe80:1234::/64", "fe80:1234::1"),
|
| 134 | 134 |
}, |
| ... | ... |
@@ -136,7 +136,7 @@ func TestBridgeICC(t *testing.T) {
|
| 136 | 136 |
}, |
| 137 | 137 |
{
|
| 138 | 138 |
name: "IPv6 non-internal network with SLAAC LL address", |
| 139 |
- bridgeOpts: []func(*networktypes.CreateOptions){
|
|
| 139 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){
|
|
| 140 | 140 |
network.WithIPv6(), |
| 141 | 141 |
network.WithIPAM("fdf1:a844:380c:b247::/64", "fdf1:a844:380c:b247::1"),
|
| 142 | 142 |
}, |
| ... | ... |
@@ -148,7 +148,7 @@ func TestBridgeICC(t *testing.T) {
|
| 148 | 148 |
}, |
| 149 | 149 |
{
|
| 150 | 150 |
name: "IPv6 internal network with SLAAC LL address", |
| 151 |
- bridgeOpts: []func(*networktypes.CreateOptions){
|
|
| 151 |
+ bridgeOpts: []func(*client.NetworkCreateOptions){
|
|
| 152 | 152 |
network.WithIPv6(), |
| 153 | 153 |
network.WithIPAM("fdf1:a844:380c:b247::/64", "fdf1:a844:380c:b247::1"),
|
| 154 | 154 |
}, |
| ... | ... |
@@ -234,8 +234,8 @@ func TestBridgeINC(t *testing.T) {
|
| 234 | 234 |
defer c.Close() |
| 235 | 235 |
|
| 236 | 236 |
type bridgesOpts struct {
|
| 237 |
- bridge1Opts []func(*networktypes.CreateOptions) |
|
| 238 |
- bridge2Opts []func(*networktypes.CreateOptions) |
|
| 237 |
+ bridge1Opts []func(*client.NetworkCreateOptions) |
|
| 238 |
+ bridge2Opts []func(*client.NetworkCreateOptions) |
|
| 239 | 239 |
} |
| 240 | 240 |
|
| 241 | 241 |
testcases := []struct {
|
| ... | ... |
@@ -248,27 +248,27 @@ func TestBridgeINC(t *testing.T) {
|
| 248 | 248 |
{
|
| 249 | 249 |
name: "IPv4 non-internal network", |
| 250 | 250 |
bridges: bridgesOpts{
|
| 251 |
- bridge1Opts: []func(*networktypes.CreateOptions){},
|
|
| 252 |
- bridge2Opts: []func(*networktypes.CreateOptions){},
|
|
| 251 |
+ bridge1Opts: []func(*client.NetworkCreateOptions){},
|
|
| 252 |
+ bridge2Opts: []func(*client.NetworkCreateOptions){},
|
|
| 253 | 253 |
}, |
| 254 | 254 |
stdout: "1 packets transmitted, 0 packets received", |
| 255 | 255 |
}, |
| 256 | 256 |
{
|
| 257 | 257 |
name: "IPv4 internal network", |
| 258 | 258 |
bridges: bridgesOpts{
|
| 259 |
- bridge1Opts: []func(*networktypes.CreateOptions){network.WithInternal()},
|
|
| 260 |
- bridge2Opts: []func(*networktypes.CreateOptions){network.WithInternal()},
|
|
| 259 |
+ bridge1Opts: []func(*client.NetworkCreateOptions){network.WithInternal()},
|
|
| 260 |
+ bridge2Opts: []func(*client.NetworkCreateOptions){network.WithInternal()},
|
|
| 261 | 261 |
}, |
| 262 | 262 |
stderr: "sendto: Network is unreachable", |
| 263 | 263 |
}, |
| 264 | 264 |
{
|
| 265 | 265 |
name: "IPv6 ULA on non-internal network", |
| 266 | 266 |
bridges: bridgesOpts{
|
| 267 |
- bridge1Opts: []func(*networktypes.CreateOptions){
|
|
| 267 |
+ bridge1Opts: []func(*client.NetworkCreateOptions){
|
|
| 268 | 268 |
network.WithIPv6(), |
| 269 | 269 |
network.WithIPAM("fdf1:a844:380c:b200::/64", "fdf1:a844:380c:b200::1"),
|
| 270 | 270 |
}, |
| 271 |
- bridge2Opts: []func(*networktypes.CreateOptions){
|
|
| 271 |
+ bridge2Opts: []func(*client.NetworkCreateOptions){
|
|
| 272 | 272 |
network.WithIPv6(), |
| 273 | 273 |
network.WithIPAM("fdf1:a844:380c:b247::/64", "fdf1:a844:380c:b247::1"),
|
| 274 | 274 |
}, |
| ... | ... |
@@ -279,12 +279,12 @@ func TestBridgeINC(t *testing.T) {
|
| 279 | 279 |
{
|
| 280 | 280 |
name: "IPv6 ULA on internal network", |
| 281 | 281 |
bridges: bridgesOpts{
|
| 282 |
- bridge1Opts: []func(*networktypes.CreateOptions){
|
|
| 282 |
+ bridge1Opts: []func(*client.NetworkCreateOptions){
|
|
| 283 | 283 |
network.WithIPv6(), |
| 284 | 284 |
network.WithInternal(), |
| 285 | 285 |
network.WithIPAM("fdf1:a844:390c:b200::/64", "fdf1:a844:390c:b200::1"),
|
| 286 | 286 |
}, |
| 287 |
- bridge2Opts: []func(*networktypes.CreateOptions){
|
|
| 287 |
+ bridge2Opts: []func(*client.NetworkCreateOptions){
|
|
| 288 | 288 |
network.WithIPv6(), |
| 289 | 289 |
network.WithInternal(), |
| 290 | 290 |
network.WithIPAM("fdf1:a844:390c:b247::/64", "fdf1:a844:390c:b247::1"),
|
| ... | ... |
@@ -1543,7 +1543,7 @@ func TestAdvertiseAddresses(t *testing.T) {
|
| 1543 | 1543 |
|
| 1544 | 1544 |
testcases := []struct {
|
| 1545 | 1545 |
name string |
| 1546 |
- netOpts []func(*networktypes.CreateOptions) |
|
| 1546 |
+ netOpts []func(*client.NetworkCreateOptions) |
|
| 1547 | 1547 |
ipv6LinkLocal bool |
| 1548 | 1548 |
stopCtr2After time.Duration |
| 1549 | 1549 |
expNetCreateErr string |
| ... | ... |
@@ -1558,21 +1558,21 @@ func TestAdvertiseAddresses(t *testing.T) {
|
| 1558 | 1558 |
}, |
| 1559 | 1559 |
{
|
| 1560 | 1560 |
name: "disable advertise addrs", |
| 1561 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1561 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1562 | 1562 |
network.WithOption(netlabel.AdvertiseAddrNMsgs, "0"), |
| 1563 | 1563 |
}, |
| 1564 | 1564 |
expNoMACUpdate: true, |
| 1565 | 1565 |
}, |
| 1566 | 1566 |
{
|
| 1567 | 1567 |
name: "single message", |
| 1568 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1568 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1569 | 1569 |
network.WithOption(netlabel.AdvertiseAddrNMsgs, "1"), |
| 1570 | 1570 |
}, |
| 1571 | 1571 |
expNMsgs: 1, |
| 1572 | 1572 |
}, |
| 1573 | 1573 |
{
|
| 1574 | 1574 |
name: "min interval", |
| 1575 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1575 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1576 | 1576 |
network.WithOption(netlabel.AdvertiseAddrIntervalMs, "100"), |
| 1577 | 1577 |
}, |
| 1578 | 1578 |
expNMsgs: 3, |
| ... | ... |
@@ -1580,7 +1580,7 @@ func TestAdvertiseAddresses(t *testing.T) {
|
| 1580 | 1580 |
}, |
| 1581 | 1581 |
{
|
| 1582 | 1582 |
name: "cancel", |
| 1583 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1583 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1584 | 1584 |
network.WithOption(netlabel.AdvertiseAddrIntervalMs, "2000"), |
| 1585 | 1585 |
}, |
| 1586 | 1586 |
stopCtr2After: 200 * time.Millisecond, |
| ... | ... |
@@ -1594,42 +1594,42 @@ func TestAdvertiseAddresses(t *testing.T) {
|
| 1594 | 1594 |
}, |
| 1595 | 1595 |
{
|
| 1596 | 1596 |
name: "interval too short", |
| 1597 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1597 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1598 | 1598 |
network.WithOption(netlabel.AdvertiseAddrIntervalMs, "99"), |
| 1599 | 1599 |
}, |
| 1600 | 1600 |
expNetCreateErr: "Error response from daemon: com.docker.network.advertise_addr_ms must be in the range 100 to 2000", |
| 1601 | 1601 |
}, |
| 1602 | 1602 |
{
|
| 1603 | 1603 |
name: "interval too long", |
| 1604 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1604 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1605 | 1605 |
network.WithOption(netlabel.AdvertiseAddrIntervalMs, "2001"), |
| 1606 | 1606 |
}, |
| 1607 | 1607 |
expNetCreateErr: "Error response from daemon: com.docker.network.advertise_addr_ms must be in the range 100 to 2000", |
| 1608 | 1608 |
}, |
| 1609 | 1609 |
{
|
| 1610 | 1610 |
name: "nonsense interval", |
| 1611 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1611 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1612 | 1612 |
network.WithOption(netlabel.AdvertiseAddrIntervalMs, "nonsense"), |
| 1613 | 1613 |
}, |
| 1614 | 1614 |
expNetCreateErr: `Error response from daemon: value for option com.docker.network.advertise_addr_ms "nonsense" must be integer milliseconds`, |
| 1615 | 1615 |
}, |
| 1616 | 1616 |
{
|
| 1617 | 1617 |
name: "negative msg count", |
| 1618 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1618 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1619 | 1619 |
network.WithOption(netlabel.AdvertiseAddrNMsgs, "-1"), |
| 1620 | 1620 |
}, |
| 1621 | 1621 |
expNetCreateErr: "Error response from daemon: com.docker.network.advertise_addr_nmsgs must be in the range 0 to 3", |
| 1622 | 1622 |
}, |
| 1623 | 1623 |
{
|
| 1624 | 1624 |
name: "too many msgs", |
| 1625 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1625 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1626 | 1626 |
network.WithOption(netlabel.AdvertiseAddrNMsgs, "4"), |
| 1627 | 1627 |
}, |
| 1628 | 1628 |
expNetCreateErr: "Error response from daemon: com.docker.network.advertise_addr_nmsgs must be in the range 0 to 3", |
| 1629 | 1629 |
}, |
| 1630 | 1630 |
{
|
| 1631 | 1631 |
name: "nonsense msg count", |
| 1632 |
- netOpts: []func(*networktypes.CreateOptions){
|
|
| 1632 |
+ netOpts: []func(*client.NetworkCreateOptions){
|
|
| 1633 | 1633 |
network.WithOption(netlabel.AdvertiseAddrNMsgs, "nonsense"), |
| 1634 | 1634 |
}, |
| 1635 | 1635 |
expNetCreateErr: `Error response from daemon: value for option com.docker.network.advertise_addr_nmsgs "nonsense" must be an integer`, |
| ... | ... |
@@ -1642,7 +1642,7 @@ func TestAdvertiseAddresses(t *testing.T) {
|
| 1642 | 1642 |
|
| 1643 | 1643 |
const netName = "dsnet" |
| 1644 | 1644 |
const brName = "br-advaddr" |
| 1645 |
- netOpts := append([]func(*networktypes.CreateOptions){
|
|
| 1645 |
+ netOpts := append([]func(*client.NetworkCreateOptions){
|
|
| 1646 | 1646 |
network.WithOption(bridge.BridgeName, brName), |
| 1647 | 1647 |
network.WithIPv6(), |
| 1648 | 1648 |
network.WithIPAM("172.22.22.0/24", "172.22.22.1"),
|
| ... | ... |
@@ -108,7 +108,7 @@ func TestDisableNAT(t *testing.T) {
|
| 108 | 108 |
ctx := testutil.StartSpan(ctx, t) |
| 109 | 109 |
|
| 110 | 110 |
const netName = "testnet" |
| 111 |
- nwOpts := []func(options *networktypes.CreateOptions){
|
|
| 111 |
+ nwOpts := []func(options *client.NetworkCreateOptions){
|
|
| 112 | 112 |
network.WithIPv6(), |
| 113 | 113 |
network.WithIPAM("fd2a:a2c3:4448::/64", "fd2a:a2c3:4448::1"),
|
| 114 | 114 |
} |
| ... | ... |
@@ -358,7 +358,7 @@ func TestAccessPublishedPortFromHost(t *testing.T) {
|
| 358 | 358 |
defer c.Close() |
| 359 | 359 |
|
| 360 | 360 |
bridgeName := fmt.Sprintf("nat-from-host-%d", tcID)
|
| 361 |
- bridgeOpts := []func(options *networktypes.CreateOptions){
|
|
| 361 |
+ bridgeOpts := []func(options *client.NetworkCreateOptions){
|
|
| 362 | 362 |
network.WithDriver("bridge"),
|
| 363 | 363 |
network.WithOption(bridge.BridgeName, bridgeName), |
| 364 | 364 |
} |
| ... | ... |
@@ -1290,7 +1290,7 @@ func testDirectRemoteAccessOnExposedPort(t *testing.T, ctx context.Context, d *d |
| 1290 | 1290 |
|
| 1291 | 1291 |
testutil.StartSpan(ctx, t) |
| 1292 | 1292 |
|
| 1293 |
- nwOpts := []func(*networktypes.CreateOptions){
|
|
| 1293 |
+ nwOpts := []func(*client.NetworkCreateOptions){
|
|
| 1294 | 1294 |
network.WithIPAM(tc.gwAddr.Masked().String(), tc.gwAddr.Addr().String()), |
| 1295 | 1295 |
network.WithOption(bridge.IPv4GatewayMode, tc.gwMode), |
| 1296 | 1296 |
network.WithOption(bridge.IPv6GatewayMode, tc.gwMode), |
| ... | ... |
@@ -21,16 +21,7 @@ const ( |
| 21 | 21 |
|
| 22 | 22 |
// CreateRequest is the request message sent to the server for network create call. |
| 23 | 23 |
type CreateRequest struct {
|
| 24 |
- CreateOptions |
|
| 25 |
- Name string // Name is the requested name of the network. |
|
| 26 |
- |
|
| 27 |
- // Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client |
|
| 28 |
- // package to older daemons. |
|
| 29 |
- CheckDuplicate *bool `json:",omitempty"` |
|
| 30 |
-} |
|
| 31 |
- |
|
| 32 |
-// CreateOptions holds options to create a network. |
|
| 33 |
-type CreateOptions struct {
|
|
| 24 |
+ Name string // Name is the requested name of the network. |
|
| 34 | 25 |
Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`) |
| 35 | 26 |
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level). |
| 36 | 27 |
EnableIPv4 *bool `json:",omitempty"` // EnableIPv4 represents whether to enable IPv4. |
| ... | ... |
@@ -43,6 +34,10 @@ type CreateOptions struct {
|
| 43 | 43 |
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]. |
| 44 | 44 |
Options map[string]string // Options specifies the network-specific options to use for when creating the network. |
| 45 | 45 |
Labels map[string]string // Labels holds metadata specific to the network being created. |
| 46 |
+ |
|
| 47 |
+ // Deprecated: CheckDuplicate is deprecated since API v1.44, but it defaults to true when sent by the client |
|
| 48 |
+ // package to older daemons. |
|
| 49 |
+ CheckDuplicate *bool `json:",omitempty"` |
|
| 46 | 50 |
} |
| 47 | 51 |
|
| 48 | 52 |
// Inspect is the body of the "get network" http response message. |
| ... | ... |
@@ -129,7 +129,7 @@ type ImageAPIClient interface {
|
| 129 | 129 |
// NetworkAPIClient defines API client methods for the networks |
| 130 | 130 |
type NetworkAPIClient interface {
|
| 131 | 131 |
NetworkConnect(ctx context.Context, network, container string, config *network.EndpointSettings) error |
| 132 |
- NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) |
|
| 132 |
+ NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) |
|
| 133 | 133 |
NetworkDisconnect(ctx context.Context, network, container string, force bool) error |
| 134 | 134 |
NetworkInspect(ctx context.Context, network string, options NetworkInspectOptions) (network.Inspect, error) |
| 135 | 135 |
NetworkInspectWithRaw(ctx context.Context, network string, options NetworkInspectOptions) (network.Inspect, []byte, error) |
| ... | ... |
@@ -9,7 +9,7 @@ import ( |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 | 11 |
// NetworkCreate creates a new network in the docker host. |
| 12 |
-func (cli *Client) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) {
|
|
| 12 |
+func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) {
|
|
| 13 | 13 |
// Make sure we negotiated (if the client is configured to do so), |
| 14 | 14 |
// as code below contains API-version specific handling of options. |
| 15 | 15 |
// |
| ... | ... |
@@ -20,8 +20,19 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options netwo |
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 | 22 |
networkCreateRequest := network.CreateRequest{
|
| 23 |
- CreateOptions: options, |
|
| 24 |
- Name: name, |
|
| 23 |
+ Name: name, |
|
| 24 |
+ Driver: options.Driver, |
|
| 25 |
+ Scope: options.Scope, |
|
| 26 |
+ EnableIPv4: options.EnableIPv4, |
|
| 27 |
+ EnableIPv6: options.EnableIPv6, |
|
| 28 |
+ IPAM: options.IPAM, |
|
| 29 |
+ Internal: options.Internal, |
|
| 30 |
+ Attachable: options.Attachable, |
|
| 31 |
+ Ingress: options.Ingress, |
|
| 32 |
+ ConfigOnly: options.ConfigOnly, |
|
| 33 |
+ ConfigFrom: options.ConfigFrom, |
|
| 34 |
+ Options: options.Options, |
|
| 35 |
+ Labels: options.Labels, |
|
| 25 | 36 |
} |
| 26 | 37 |
if versions.LessThan(cli.version, "1.44") {
|
| 27 | 38 |
enabled := true |
| 28 | 39 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,19 @@ |
| 0 |
+package client |
|
| 1 |
+ |
|
| 2 |
+import "github.com/moby/moby/api/types/network" |
|
| 3 |
+ |
|
| 4 |
+// NetworkCreateOptions holds options to create a network. |
|
| 5 |
+type NetworkCreateOptions struct {
|
|
| 6 |
+ Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`) |
|
| 7 |
+ Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level). |
|
| 8 |
+ EnableIPv4 *bool // EnableIPv4 represents whether to enable IPv4. |
|
| 9 |
+ EnableIPv6 *bool // EnableIPv6 represents whether to enable IPv6. |
|
| 10 |
+ IPAM *network.IPAM // IPAM is the network's IP Address Management. |
|
| 11 |
+ Internal bool // Internal represents if the network is used internal only. |
|
| 12 |
+ Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode. |
|
| 13 |
+ Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster. |
|
| 14 |
+ ConfigOnly bool // ConfigOnly creates a config-only network. Config-only networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services. |
|
| 15 |
+ ConfigFrom *network.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]. |
|
| 16 |
+ Options map[string]string // Options specifies the network-specific options to use for when creating the network. |
|
| 17 |
+ Labels map[string]string // Labels holds metadata specific to the network being created. |
|
| 18 |
+} |