Skip to content

Commit d22d8a7

Browse files
committed
runconfig: deprecate IsPreDefinedNetwork
Move the function internal to the daemon, where it's used. Deliberately not mentioning the new location, as this function should not be used externally. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent a24af26 commit d22d8a7

9 files changed

Lines changed: 39 additions & 17 deletions

File tree

daemon/cluster/networks.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/docker/docker/daemon/cluster/convert"
1212
networkSettings "github.com/docker/docker/daemon/network"
1313
"github.com/docker/docker/errdefs"
14-
"github.com/docker/docker/runconfig"
1514
swarmapi "github.com/moby/swarmkit/v2/api"
1615
"github.com/pkg/errors"
1716
)
@@ -269,7 +268,7 @@ func (c *Cluster) DetachNetwork(target string, containerID string) error {
269268

270269
// CreateNetwork creates a new cluster managed network.
271270
func (c *Cluster) CreateNetwork(s network.CreateRequest) (string, error) {
272-
if runconfig.IsPreDefinedNetwork(s.Name) {
271+
if networkSettings.IsPredefined(s.Name) {
273272
err := notAllowedError(fmt.Sprintf("%s is a pre-defined network and cannot be created", s.Name))
274273
return "", errors.WithStack(err)
275274
}
@@ -314,7 +313,7 @@ func (c *Cluster) populateNetworkID(ctx context.Context, client swarmapi.Control
314313
apiNetwork, err := getNetwork(ctx, client, nw.Target)
315314
if err != nil {
316315
ln, _ := c.config.Backend.FindNetwork(nw.Target)
317-
if ln != nil && runconfig.IsPreDefinedNetwork(ln.Name()) {
316+
if ln != nil && networkSettings.IsPredefined(ln.Name()) {
318317
// Need to retrieve the corresponding predefined swarm network
319318
// and use its id for the request.
320319
apiNetwork, err = getNetwork(ctx, client, ln.Name())

daemon/network.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
lntypes "github.com/docker/docker/libnetwork/types"
3232
"github.com/docker/docker/opts"
3333
"github.com/docker/docker/pkg/plugingetter"
34-
"github.com/docker/docker/runconfig"
3534
"github.com/docker/go-connections/nat"
3635
)
3736

@@ -290,7 +289,7 @@ func (daemon *Daemon) CreateNetwork(create networktypes.CreateRequest) (*network
290289
}
291290

292291
func (daemon *Daemon) createNetwork(cfg *config.Config, create networktypes.CreateRequest, id string, agent bool) (*networktypes.CreateResponse, error) {
293-
if runconfig.IsPreDefinedNetwork(create.Name) {
292+
if network.IsPredefined(create.Name) {
294293
return nil, PredefinedNetworkError(create.Name)
295294
}
296295

@@ -543,13 +542,13 @@ func (daemon *Daemon) DeleteNetwork(networkID string) error {
543542
}
544543

545544
func (daemon *Daemon) deleteNetwork(nw *libnetwork.Network, dynamic bool) error {
546-
if runconfig.IsPreDefinedNetwork(nw.Name()) && !dynamic {
545+
if network.IsPredefined(nw.Name()) && !dynamic {
547546
err := fmt.Errorf("%s is a pre-defined network and cannot be removed", nw.Name())
548547
return errdefs.Forbidden(err)
549548
}
550549

551550
if dynamic && !nw.Dynamic() {
552-
if runconfig.IsPreDefinedNetwork(nw.Name()) {
551+
if network.IsPredefined(nw.Name()) {
553552
// Predefined networks now support swarm services. Make this
554553
// a no-op when cluster requests to remove the predefined network.
555554
return nil

daemon/network/filter.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"github.com/docker/docker/api/types/filters"
55
"github.com/docker/docker/api/types/network"
66
"github.com/docker/docker/errdefs"
7-
"github.com/docker/docker/runconfig"
87
"github.com/pkg/errors"
98
)
109

@@ -94,9 +93,9 @@ func filterNetworkByUse(nws []network.Inspect, danglingOnly bool) []network.Insp
9493

9594
filterFunc := func(nw network.Inspect) bool {
9695
if danglingOnly {
97-
return !runconfig.IsPreDefinedNetwork(nw.Name) && len(nw.Containers) == 0 && len(nw.Services) == 0
96+
return !IsPredefined(nw.Name) && len(nw.Containers) == 0 && len(nw.Services) == 0
9897
}
99-
return runconfig.IsPreDefinedNetwork(nw.Name) || len(nw.Containers) > 0 || len(nw.Services) > 0
98+
return IsPredefined(nw.Name) || len(nw.Containers) > 0 || len(nw.Services) > 0
10099
}
101100

102101
for _, nw := range nws {
@@ -113,13 +112,13 @@ func filterNetworkByType(nws []network.Inspect, netType string) ([]network.Inspe
113112
switch netType {
114113
case "builtin":
115114
for _, nw := range nws {
116-
if runconfig.IsPreDefinedNetwork(nw.Name) {
115+
if IsPredefined(nw.Name) {
117116
retNws = append(retNws, nw)
118117
}
119118
}
120119
case "custom":
121120
for _, nw := range nws {
122-
if !runconfig.IsPreDefinedNetwork(nw.Name) {
121+
if !IsPredefined(nw.Name) {
123122
retNws = append(retNws, nw)
124123
}
125124
}

daemon/network/network_mode.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ package network
55
// ([network.NetworkBridge]), and "nat" ([network.NetworkNat]) for Windows
66
// containers.
77
const DefaultNetwork = defaultNetwork
8+
9+
// IsPredefined indicates if a network is predefined by the daemon.
10+
func IsPredefined(network string) bool {
11+
// TODO(thaJeztah): check if we can align the check for both platforms
12+
return isPreDefined(network)
13+
}

daemon/network/network_mode_unix.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
package network
44

5-
import "github.com/docker/docker/api/types/network"
5+
import (
6+
"github.com/docker/docker/api/types/container"
7+
"github.com/docker/docker/api/types/network"
8+
)
69

710
const defaultNetwork = network.NetworkBridge
11+
12+
func isPreDefined(network string) bool {
13+
n := container.NetworkMode(network)
14+
return n.IsBridge() || n.IsHost() || n.IsNone() || n.IsDefault()
15+
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package network
22

3-
import "github.com/docker/docker/api/types/network"
3+
import (
4+
"github.com/docker/docker/api/types/container"
5+
"github.com/docker/docker/api/types/network"
6+
)
47

58
const defaultNetwork = network.NetworkNat
9+
10+
func isPreDefined(network string) bool {
11+
return !container.NetworkMode(network).IsUserDefined()
12+
}

daemon/prune.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"github.com/docker/docker/api/types/filters"
1515
"github.com/docker/docker/api/types/network"
1616
timetypes "github.com/docker/docker/api/types/time"
17+
networkSettings "github.com/docker/docker/daemon/network"
1718
"github.com/docker/docker/errdefs"
1819
"github.com/docker/docker/libnetwork"
19-
"github.com/docker/docker/runconfig"
2020
"github.com/pkg/errors"
2121
)
2222

@@ -121,7 +121,7 @@ func (daemon *Daemon) localNetworksPrune(ctx context.Context, pruneFilters filte
121121
return false
122122
}
123123
nwName := nw.Name()
124-
if runconfig.IsPreDefinedNetwork(nwName) {
124+
if networkSettings.IsPredefined(nwName) {
125125
return false
126126
}
127127
if len(nw.Endpoints()) > 0 {

runconfig/hostconfig_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ func DefaultDaemonNetworkMode() container.NetworkMode {
2020
}
2121

2222
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
23+
//
24+
// Deprecated: this function is no longer used and will be removed in the next release.
2325
func IsPreDefinedNetwork(network string) bool {
2426
n := container.NetworkMode(network)
2527
return n.IsBridge() || n.IsHost() || n.IsNone() || n.IsDefault()

runconfig/hostconfig_windows.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ func DefaultDaemonNetworkMode() container.NetworkMode {
1616
return network.NetworkNat
1717
}
1818

19-
// IsPreDefinedNetwork indicates if a network is predefined by the daemon
19+
// IsPreDefinedNetwork indicates if a network is predefined by the daemon.
20+
//
21+
// Deprecated: this function is no longer used and will be removed in the next release.
2022
func IsPreDefinedNetwork(network string) bool {
2123
return !container.NetworkMode(network).IsUserDefined()
2224
}

0 commit comments

Comments
 (0)