Skip to content

Commit 8e91b64

Browse files
committed
runconfig: deprecate DefaultDaemonNetworkMode, move to daemon/network
This function returns the default network to use for the daemon platform; moving this to a location separate from runconfig, which is planned to be dismantled and moved to the API. While it might be convenient to move this utility inside api/types/container, we don't want to advertise this function too widely, as the default returned can ONLY be considered correct when ran on the daemon-side. An alternative would be to introduce an argument (daemonPlatform), which isn't very convenient to use. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent caf502a commit 8e91b64

14 files changed

Lines changed: 104 additions & 85 deletions

File tree

api/server/router/container/container_routes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/docker/docker/api/types/network"
2323
"github.com/docker/docker/api/types/versions"
2424
containerpkg "github.com/docker/docker/container"
25+
networkSettings "github.com/docker/docker/daemon/network"
2526
"github.com/docker/docker/errdefs"
2627
"github.com/docker/docker/libnetwork/netlabel"
2728
"github.com/docker/docker/pkg/ioutils"
@@ -501,7 +502,7 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
501502
// Note that this is not the only place where this conversion has to be
502503
// done (as there are various other places where containers get created).
503504
if hostConfig.NetworkMode == "" || hostConfig.NetworkMode.IsDefault() {
504-
hostConfig.NetworkMode = runconfig.DefaultDaemonNetworkMode()
505+
hostConfig.NetworkMode = networkSettings.DefaultNetwork
505506
if nw, ok := networkingConfig.EndpointsConfig[network.NetworkDefault]; ok {
506507
networkingConfig.EndpointsConfig[hostConfig.NetworkMode.NetworkName()] = nw
507508
delete(networkingConfig.EndpointsConfig, network.NetworkDefault)

builder/dockerfile/internals.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
"github.com/docker/docker/api/types/container"
1818
"github.com/docker/docker/api/types/network"
1919
"github.com/docker/docker/builder"
20+
networkSettings "github.com/docker/docker/daemon/network"
2021
"github.com/docker/docker/image"
2122
"github.com/docker/docker/pkg/archive"
2223
"github.com/docker/docker/pkg/chrootarchive"
2324
"github.com/docker/docker/pkg/stringid"
24-
"github.com/docker/docker/runconfig"
2525
"github.com/docker/go-connections/nat"
2626
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2727
"github.com/pkg/errors"
@@ -382,7 +382,7 @@ func hostConfigFromOptions(options *types.ImageBuildOptions) *container.HostConf
382382
// This is in line with what the ContainerCreate API endpoint does.
383383
networkMode := options.NetworkMode
384384
if networkMode == "" || networkMode == network.NetworkDefault {
385-
networkMode = runconfig.DefaultDaemonNetworkMode().NetworkName()
385+
networkMode = networkSettings.DefaultNetwork
386386
}
387387

388388
hc := &container.HostConfig{

daemon/cluster/executor/container/adapter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"github.com/docker/docker/daemon"
2424
"github.com/docker/docker/daemon/cluster/convert"
2525
executorpkg "github.com/docker/docker/daemon/cluster/executor"
26+
networkSettings "github.com/docker/docker/daemon/network"
2627
"github.com/docker/docker/libnetwork"
27-
"github.com/docker/docker/runconfig"
2828
volumeopts "github.com/docker/docker/volume/service/opts"
2929
gogotypes "github.com/gogo/protobuf/types"
3030
"github.com/moby/swarmkit/v2/agent/exec"
@@ -305,10 +305,10 @@ func (c *containerAdapter) create(ctx context.Context) error {
305305
// need to make this normalization happen once we're sure we won't make a
306306
// cross-OS API call.
307307
if hostConfig.NetworkMode == "" || hostConfig.NetworkMode.IsDefault() {
308-
hostConfig.NetworkMode = runconfig.DefaultDaemonNetworkMode()
308+
hostConfig.NetworkMode = networkSettings.DefaultNetwork
309309
if v, ok := netConfig.EndpointsConfig[network.NetworkDefault]; ok {
310310
delete(netConfig.EndpointsConfig, network.NetworkDefault)
311-
netConfig.EndpointsConfig[runconfig.DefaultDaemonNetworkMode().NetworkName()] = v
311+
netConfig.EndpointsConfig[networkSettings.DefaultNetwork] = v
312312
}
313313
}
314314

daemon/cluster/networks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/docker/docker/api/types/network"
1010
types "github.com/docker/docker/api/types/swarm"
1111
"github.com/docker/docker/daemon/cluster/convert"
12-
internalnetwork "github.com/docker/docker/daemon/network"
12+
networkSettings "github.com/docker/docker/daemon/network"
1313
"github.com/docker/docker/errdefs"
1414
"github.com/docker/docker/runconfig"
1515
swarmapi "github.com/moby/swarmkit/v2/api"
@@ -39,7 +39,7 @@ func (c *Cluster) GetNetworks(filter filters.Args) ([]network.Inspect, error) {
3939
}
4040
filterPredefinedNetworks(&list)
4141

42-
return internalnetwork.FilterNetworks(list, filter)
42+
return networkSettings.FilterNetworks(list, filter)
4343
}
4444

4545
func filterPredefinedNetworks(networks *[]network.Inspect) {

daemon/container_operations.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (daemon *Daemon) buildSandboxOptions(cfg *config.Config, ctr *container.Con
160160
// Legacy Link feature is supported only for the default bridge network.
161161
// return if this call to build join options is not for default bridge network
162162
// Legacy Link is only supported by docker run --link
163-
defaultNetName := runconfig.DefaultDaemonNetworkMode().NetworkName()
163+
defaultNetName := network.DefaultNetwork
164164
bridgeSettings, ok := ctr.NetworkSettings.Networks[defaultNetName]
165165
if !ok || bridgeSettings.EndpointSettings == nil || bridgeSettings.EndpointID == "" {
166166
return sboxOptions, nil
@@ -268,7 +268,7 @@ func (daemon *Daemon) updateEndpointNetworkSettings(cfg *config.Config, ctr *con
268268
return err
269269
}
270270

271-
if ctr.HostConfig.NetworkMode == runconfig.DefaultDaemonNetworkMode() {
271+
if ctr.HostConfig.NetworkMode == network.DefaultNetwork {
272272
ctr.NetworkSettings.Bridge = cfg.BridgeConfig.Iface
273273
}
274274

@@ -296,7 +296,7 @@ func (daemon *Daemon) updateNetwork(cfg *config.Config, ctr *container.Container
296296
if err != nil {
297297
continue
298298
}
299-
if sn.Name() == runconfig.DefaultDaemonNetworkMode().NetworkName() {
299+
if sn.Name() == network.DefaultNetwork {
300300
n = sn
301301
break
302302
}
@@ -505,7 +505,7 @@ func (daemon *Daemon) allocateNetwork(ctx context.Context, cfg *config.Config, c
505505
// network mode support link and we need do some setting
506506
// on sandbox initialize for link, but the sandbox only be initialized
507507
// on first network connecting.
508-
defaultNetName := runconfig.DefaultDaemonNetworkMode().NetworkName()
508+
defaultNetName := network.DefaultNetwork
509509
if nConf, ok := ctr.NetworkSettings.Networks[defaultNetName]; ok {
510510
cleanOperationalData(nConf)
511511
if err := daemon.connectToNetwork(ctx, cfg, ctr, defaultNetName, nConf, updateSettings); err != nil {

daemon/container_operations_unix.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"github.com/docker/docker/container"
1515
"github.com/docker/docker/daemon/config"
1616
"github.com/docker/docker/daemon/links"
17+
"github.com/docker/docker/daemon/network"
1718
"github.com/docker/docker/errdefs"
1819
"github.com/docker/docker/libnetwork"
1920
"github.com/docker/docker/pkg/idtools"
2021
"github.com/docker/docker/pkg/process"
2122
"github.com/docker/docker/pkg/stringid"
22-
"github.com/docker/docker/runconfig"
2323
"github.com/moby/sys/mount"
2424
"github.com/opencontainers/selinux/go-selinux/label"
2525
"github.com/pkg/errors"
@@ -30,7 +30,7 @@ func (daemon *Daemon) setupLinkedContainers(ctr *container.Container) ([]string,
3030
var env []string
3131
children := daemon.children(ctr)
3232

33-
bridgeSettings := ctr.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()]
33+
bridgeSettings := ctr.NetworkSettings.Networks[network.DefaultNetwork]
3434
if bridgeSettings == nil || bridgeSettings.EndpointSettings == nil {
3535
return nil, nil
3636
}
@@ -40,7 +40,7 @@ func (daemon *Daemon) setupLinkedContainers(ctr *container.Container) ([]string,
4040
return nil, fmt.Errorf("Cannot link to a non running container: %s AS %s", child.Name, linkAlias)
4141
}
4242

43-
childBridgeSettings := child.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()]
43+
childBridgeSettings := child.NetworkSettings.Networks[network.DefaultNetwork]
4444
if childBridgeSettings == nil || childBridgeSettings.EndpointSettings == nil {
4545
return nil, fmt.Errorf("container %s not attached to default bridge network", child.ID)
4646
}
@@ -402,7 +402,7 @@ func killProcessDirectly(ctr *container.Container) error {
402402

403403
func isLinkable(child *container.Container) bool {
404404
// A container is linkable only if it belongs to the default network
405-
_, ok := child.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()]
405+
_, ok := child.NetworkSettings.Networks[network.DefaultNetwork]
406406
return ok
407407
}
408408

daemon/daemon.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ import (
7575
pluginexec "github.com/docker/docker/plugin/executor/containerd"
7676
refstore "github.com/docker/docker/reference"
7777
"github.com/docker/docker/registry"
78-
"github.com/docker/docker/runconfig"
7978
volumesservice "github.com/docker/docker/volume/service"
8079
"github.com/moby/buildkit/util/grpcerrors"
8180
"github.com/moby/buildkit/util/resolver"
@@ -391,7 +390,7 @@ func (daemon *Daemon) restore(cfg *configStore) error {
391390
//
392391
// TODO(aker): remove this migration code once the next LTM version of MCR is released.
393392
if c.HostConfig.NetworkMode.IsDefault() {
394-
c.HostConfig.NetworkMode = runconfig.DefaultDaemonNetworkMode()
393+
c.HostConfig.NetworkMode = network.DefaultNetwork
395394
if nw, ok := c.NetworkSettings.Networks[networktypes.NetworkDefault]; ok {
396395
c.NetworkSettings.Networks[c.HostConfig.NetworkMode.NetworkName()] = nw
397396
delete(c.NetworkSettings.Networks, networktypes.NetworkDefault)
@@ -1486,13 +1485,11 @@ func isBridgeNetworkDisabled(conf *config.Config) bool {
14861485
}
14871486

14881487
func (daemon *Daemon) networkOptions(conf *config.Config, pg plugingetter.PluginGetter, hostID string, activeSandboxes map[string]interface{}) ([]nwconfig.Option, error) {
1489-
dd := runconfig.DefaultDaemonNetworkMode()
1490-
14911488
options := []nwconfig.Option{
14921489
nwconfig.OptionDataDir(conf.Root),
14931490
nwconfig.OptionExecRoot(conf.GetExecRoot()),
1494-
nwconfig.OptionDefaultDriver(string(dd)),
1495-
nwconfig.OptionDefaultNetwork(dd.NetworkName()),
1491+
nwconfig.OptionDefaultDriver(network.DefaultNetwork),
1492+
nwconfig.OptionDefaultNetwork(network.DefaultNetwork),
14961493
nwconfig.OptionLabels(conf.Labels),
14971494
nwconfig.OptionNetworkControlPlaneMTU(conf.NetworkControlPlaneMTU),
14981495
driverOptions(conf),

daemon/daemon_windows.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
networktypes "github.com/docker/docker/api/types/network"
1616
"github.com/docker/docker/container"
1717
"github.com/docker/docker/daemon/config"
18+
"github.com/docker/docker/daemon/network"
1819
"github.com/docker/docker/libcontainerd/local"
1920
"github.com/docker/docker/libcontainerd/remote"
2021
"github.com/docker/docker/libnetwork"
@@ -28,7 +29,6 @@ import (
2829
"github.com/docker/docker/pkg/parsers/operatingsystem"
2930
"github.com/docker/docker/pkg/sysinfo"
3031
"github.com/docker/docker/pkg/system"
31-
"github.com/docker/docker/runconfig"
3232
"github.com/pkg/errors"
3333
"golang.org/x/sys/windows"
3434
"golang.org/x/sys/windows/svc/mgr"
@@ -309,7 +309,7 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand
309309

310310
defaultNetworkExists := false
311311

312-
if network, err := daemon.netController.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil {
312+
if network, err := daemon.netController.NetworkByName(network.DefaultNetwork); err == nil {
313313
hnsid := network.DriverOptions()[winlibnetwork.HNSID]
314314
for _, v := range hnsresponse {
315315
if hnsid == v.Id {
@@ -377,10 +377,8 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand
377377

378378
// If there is no nat network create one from the first NAT network
379379
// encountered if it doesn't already exist
380-
if !defaultNetworkExists &&
381-
runconfig.DefaultDaemonNetworkMode() == containertypes.NetworkMode(strings.ToLower(v.Type)) &&
382-
n == nil {
383-
name = runconfig.DefaultDaemonNetworkMode().NetworkName()
380+
if !defaultNetworkExists && strings.EqualFold(network.DefaultNetwork, v.Type) && n == nil {
381+
name = network.DefaultNetwork
384382
defaultNetworkExists = true
385383
}
386384

@@ -407,12 +405,12 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand
407405
}
408406

409407
func initBridgeDriver(controller *libnetwork.Controller, config config.BridgeConfig) error {
410-
if _, err := controller.NetworkByName(runconfig.DefaultDaemonNetworkMode().NetworkName()); err == nil {
408+
if _, err := controller.NetworkByName(network.DefaultNetwork); err == nil {
411409
return nil
412410
}
413411

414412
netOption := map[string]string{
415-
winlibnetwork.NetworkName: runconfig.DefaultDaemonNetworkMode().NetworkName(),
413+
winlibnetwork.NetworkName: network.DefaultNetwork,
416414
}
417415

418416
var ipamOption libnetwork.NetworkOption
@@ -429,7 +427,7 @@ func initBridgeDriver(controller *libnetwork.Controller, config config.BridgeCon
429427
ipamOption = libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil)
430428
}
431429

432-
_, err := controller.NewNetwork(string(runconfig.DefaultDaemonNetworkMode()), runconfig.DefaultDaemonNetworkMode().NetworkName(), "",
430+
_, err := controller.NewNetwork(network.DefaultNetwork, network.DefaultNetwork, "",
433431
libnetwork.NetworkOptionGeneric(options.Generic{
434432
netlabel.GenericData: netOption,
435433
}),

0 commit comments

Comments
 (0)