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

bugfix: fix container can't ping outside and resolve domain names #2025

Merged
merged 1 commit into from
Aug 1, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions daemon/mgr/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ func controllerOptions(cfg network.Config) ([]nwconfig.Option, error) {

options = append(options, nwconfig.OptionDefaultDriver("bridge"))
options = append(options, nwconfig.OptionDefaultNetwork("bridge"))
options = append(options, nwconfig.OptionNetworkControlPlaneMTU(cfg.BridgeConfig.Mtu))
options = append(options, nwconfig.OptionExperimental(false))

// set bridge options
options = append(options, bridgeDriverOptions(cfg.BridgeConfig))
Expand Down
8 changes: 6 additions & 2 deletions network/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package network

// DefaultExecRoot defines the default network execute root directory.
var DefaultExecRoot = "/var/run/pouch"
var (
// DefaultExecRoot defines the default network execute root directory.
DefaultExecRoot = "/var/run/pouch"
// DefaultNetworkMtu is the default value for network MTU
DefaultNetworkMtu = 1500
)

// Config defines the network configuration.
type Config struct {
Expand Down
6 changes: 3 additions & 3 deletions network/mode/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func New(ctx context.Context, config network.BridgeConfig, manager mgr.NetworkMg
Config: []types.IPAMConfig{ipamV4Conf},
}

mtu := 1500
mtu := network.DefaultNetworkMtu
if config.Mtu != 0 {
mtu = config.Mtu
}
Expand All @@ -134,7 +134,7 @@ func New(ctx context.Context, config network.BridgeConfig, manager mgr.NetworkMg
netlabel.DriverMTU: strconv.Itoa(mtu),
bridge.EnableICC: strconv.FormatBool(true),
bridge.DefaultBindingIP: DefaultBindingIP,
bridge.EnableIPMasquerade: strconv.FormatBool(false),
bridge.EnableIPMasquerade: strconv.FormatBool(true),
},
IPAM: ipam,
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func initBridgeDevice(name string) (netlink.Link, error) {
return nil, errors.Wrap(err, "failed to set bridge device up")
}

br, err = netlink.LinkByName(DefaultBridge)
br, err = netlink.LinkByName(name)
if err != nil {
return nil, err
}
Expand Down
35 changes: 35 additions & 0 deletions test/cli_run_network_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)

// PouchRunNetworkSuite is the test suite for run CLI.
type PouchRunNetworkSuite struct{}

func init() {
check.Suite(&PouchRunNetworkSuite{})
}

// SetUpSuite does common setup in the beginning of each test suite.
func (suite *PouchRunNetworkSuite) SetUpSuite(c *check.C) {
SkipIfFalse(c, environment.IsLinux)

environment.PruneAllContainers(apiClient)

PullImage(c, busyboxImage)
}

// TestRunWithPing is to verify run container with network ping public website.
func (suite *PouchRunNetworkSuite) TestRunWithPing(c *check.C) {
name := "TestRunWithPing"

res := command.PouchRun("run", "--name", name,
busyboxImage, "ping", "-c", "10", "www.taobao.com")
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)
}