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

feature: container start with network #660

Merged
merged 1 commit into from
Feb 1, 2018

Conversation

rudyfly
Copy link
Collaborator

@rudyfly rudyfly commented Jan 29, 2018

1.Describe what this PR did
container start with network.

2.Does this pull request fix one issue?

fixes #604

3.Describe how you did it

  1. When pouchd start, it will build default bridge network 'p0', use netlink to create p0 bridge.
  2. container start with bridge network and set ip address
  3. create sandbox in libnetwork
  4. create endpoint in libnetwork
  5. new endpoint joins into sandbox
  6. set prestart hook to runc to get sandbox network.

4.Describe how to verify it

# pouch run --net bridge:172.17.0.10 --name nettest -d registry.hub.docker.com/library/busybox:latest top
# pouch exec -ti nettest sh

In container, you can get the network information. such as:

# ifconfig

image

# ping 172.17.0.1

image

5.Special notes for reviews

Signed-off-by: Rudy Zhang [email protected]

@codecov-io
Copy link

codecov-io commented Jan 29, 2018

Codecov Report

Merging #660 into master will decrease coverage by 0.11%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #660      +/-   ##
==========================================
- Coverage   10.28%   10.16%   -0.12%     
==========================================
  Files          71       71              
  Lines        3384     3422      +38     
==========================================
  Hits          348      348              
- Misses       2997     3035      +38     
  Partials       39       39
Impacted Files Coverage Δ
client/container.go 0% <0%> (ø) ⬆️
cli/create.go 0% <0%> (ø) ⬆️
cli/container.go 26.41% <0%> (-7.46%) ⬇️
cli/run.go 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25c9507...4cc4c1b. Read the comment docs.

@rudyfly
Copy link
Collaborator Author

rudyfly commented Jan 30, 2018

fix #604

container start with default bridge network.

Signed-off-by: Rudy Zhang <[email protected]>
@rudyfly
Copy link
Collaborator Author

rudyfly commented Jan 31, 2018

ping~PTAL @allencloud

@allencloud
Copy link
Collaborator

LGTM. tested well on my local machine.

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label Feb 1, 2018
@allencloud allencloud merged commit d4b0838 into AliyunContainerService:master Feb 1, 2018
switch len(arr) {
case 1:
if ipaddr := net.ParseIP(arr[0]); ipaddr != nil {
ip = arr[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, name is "", does networkingConfig.EndpointsConfig[""] make sense?

@@ -35,6 +36,7 @@ type container struct {
pidMode string
utsMode string
sysctls []string
network []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the type is slice, "networks" is better.

HostConfig: hostConfig,
ContainerConfig: config,
HostConfig: hostConfig,
NetworkingConfig: networkConfig,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NetworkingConfig or networkConfig? Why not make them consistent?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we got your point. Actually in Moby's it is NetworkingConfig, so we have not changed that yet.

for name, endpointSetting := range c.meta.NetworkSettings.Networks {
_, err := mgr.NetworkMgr.EndpointCreate(ctx, c.ID(), name, c.meta.NetworkSettings, endpointSetting)
if err != nil {
logrus.Errorf("fail to create endpoint, err: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logrus.Errorf("failed to create endpoint: %v", err)

@@ -371,6 +380,17 @@ func (mgr *ContainerManager) Start(ctx context.Context, id, detachKeys string) (
}
c.DetachKeys = detachKeys

// initialise network endpoint
if c.meta.NetworkSettings.Networks != nil && len(c.meta.NetworkSettings.Networks) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The judgement is redundant, it is ok to range map which is nil.

// set network settings
meta.NetworkSettings = &types.NetworkSettings{}
if config.NetworkingConfig.EndpointsConfig != nil &&
len(config.NetworkingConfig.EndpointsConfig) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the code above, config.NetworkingConfig.EndpointsConfig will not be nil.
Maybe the judgement of len(...) > 0 is enough.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I found this issue as well. I will fix this.

@@ -115,6 +117,28 @@ func (c *container) config() (*types.ContainerCreateConfig, error) {
},
}

if len(c.network) == 0 {
config.HostConfig.NetworkMode = "bridge"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the network mode is "none", "host" or "container"?

It seems weird to specify multiple networks in "pouch create" or "pouch run", what if the networks are conflict, one network is "container" and another is "none"? The judgement will be too complicated.
@allencloud @skoo87 WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
areas/network kind/feature LGTM one maintainer or community participant agrees to merge the pull reuqest. size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] Network ability of container
5 participants