Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23.0 backport] daemon: set docker0 subpool as the IPAM pool #45403

Merged
merged 1 commit into from Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions daemon/daemon_unix.go
Expand Up @@ -1000,6 +1000,9 @@ func initBridgeDriver(controller libnetwork.NetworkController, config *config.Co
}

ipamV4Conf.SubPool = fCIDR.String()
if ipamV4Conf.PreferredPool == "" {
ipamV4Conf.PreferredPool = fCIDR.String()
}
}

if config.BridgeConfig.DefaultGatewayIPv4 != nil {
Expand Down
28 changes: 28 additions & 0 deletions integration/daemon/daemon_test.go
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/docker/docker/testutil/daemon"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/icmd"
"gotest.tools/v3/skip"
)

Expand Down Expand Up @@ -416,3 +417,30 @@ func testLiveRestoreVolumeReferences(t *testing.T) {
runTest(t, "no")
})
}

func TestDaemonDefaultBridgeWithFixedCidrButNoBip(t *testing.T) {
skip.If(t, runtime.GOOS == "windows")

bridgeName := "ext-bridge1"
d := daemon.New(t, daemon.WithEnvVars("DOCKER_TEST_CREATE_DEFAULT_BRIDGE="+bridgeName))
defer func() {
d.Stop(t)
d.Cleanup(t)
}()

defer func() {
// No need to clean up when running this test in rootless mode, as the
// interface is deleted when the daemon is stopped and the netns
// reclaimed by the kernel.
if !testEnv.IsRootless() {
deleteInterface(t, bridgeName)
}
}()
d.StartWithBusybox(t, "--bridge", bridgeName, "--fixed-cidr", "192.168.130.0/24")
}

func deleteInterface(t *testing.T, ifName string) {
icmd.RunCommand("ip", "link", "delete", ifName).Assert(t, icmd.Success)
icmd.RunCommand("iptables", "-t", "nat", "--flush").Assert(t, icmd.Success)
icmd.RunCommand("iptables", "--flush").Assert(t, icmd.Success)
}
10 changes: 8 additions & 2 deletions libnetwork/drivers/bridge/setup_device.go
Expand Up @@ -16,8 +16,14 @@ import (
// SetupDevice create a new bridge interface/
func setupDevice(config *networkConfiguration, i *bridgeInterface) error {
// We only attempt to create the bridge when the requested device name is
// the default one.
if config.BridgeName != DefaultBridgeName && config.DefaultBridge {
// the default one. The default bridge name can be overridden with the
// DOCKER_TEST_CREATE_DEFAULT_BRIDGE env var. It should be used only for
// test purpose.
var defaultBridgeName string
if defaultBridgeName = os.Getenv("DOCKER_TEST_CREATE_DEFAULT_BRIDGE"); defaultBridgeName == "" {
defaultBridgeName = DefaultBridgeName
}
if config.BridgeName != defaultBridgeName && config.DefaultBridge {
return NonDefaultBridgeExistError(config.BridgeName)
}

Expand Down