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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-06-17 10:48:38 +02:00
parent a24af26aba
commit d22d8a78f1
9 changed files with 39 additions and 17 deletions

View File

@@ -4,7 +4,6 @@ import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/runconfig"
"github.com/pkg/errors"
)
@@ -94,9 +93,9 @@ func filterNetworkByUse(nws []network.Inspect, danglingOnly bool) []network.Insp
filterFunc := func(nw network.Inspect) bool {
if danglingOnly {
return !runconfig.IsPreDefinedNetwork(nw.Name) && len(nw.Containers) == 0 && len(nw.Services) == 0
return !IsPredefined(nw.Name) && len(nw.Containers) == 0 && len(nw.Services) == 0
}
return runconfig.IsPreDefinedNetwork(nw.Name) || len(nw.Containers) > 0 || len(nw.Services) > 0
return IsPredefined(nw.Name) || len(nw.Containers) > 0 || len(nw.Services) > 0
}
for _, nw := range nws {
@@ -113,13 +112,13 @@ func filterNetworkByType(nws []network.Inspect, netType string) ([]network.Inspe
switch netType {
case "builtin":
for _, nw := range nws {
if runconfig.IsPreDefinedNetwork(nw.Name) {
if IsPredefined(nw.Name) {
retNws = append(retNws, nw)
}
}
case "custom":
for _, nw := range nws {
if !runconfig.IsPreDefinedNetwork(nw.Name) {
if !IsPredefined(nw.Name) {
retNws = append(retNws, nw)
}
}

View File

@@ -5,3 +5,9 @@ package network
// ([network.NetworkBridge]), and "nat" ([network.NetworkNat]) for Windows
// containers.
const DefaultNetwork = defaultNetwork
// IsPredefined indicates if a network is predefined by the daemon.
func IsPredefined(network string) bool {
// TODO(thaJeztah): check if we can align the check for both platforms
return isPreDefined(network)
}

View File

@@ -2,6 +2,14 @@
package network
import "github.com/docker/docker/api/types/network"
import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
)
const defaultNetwork = network.NetworkBridge
func isPreDefined(network string) bool {
n := container.NetworkMode(network)
return n.IsBridge() || n.IsHost() || n.IsNone() || n.IsDefault()
}

View File

@@ -1,5 +1,12 @@
package network
import "github.com/docker/docker/api/types/network"
import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
)
const defaultNetwork = network.NetworkNat
func isPreDefined(network string) bool {
return !container.NetworkMode(network).IsUserDefined()
}