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: add container's network files #1403

Merged

Conversation

shaloulcy
Copy link
Contributor

@shaloulcy shaloulcy commented May 24, 2018

Signed-off-by: Eric Li lcy041536@gmail.com

Ⅰ. Describe what this PR did

Now when we start a container, it has no network files, including /etc/hosts, /etc/hostname and /etc/resolv.conf. In this PR, we will generate container's network files when container starts

Ⅱ. Does this pull request fix one issue?

fixes #1162

Ⅲ. Describe how you did it

The libnetwork will help us generate network files(/etc/hosts and /etc/resolv.conf). /etc/hostname will be generated by pouchd.

At last, we should mount it into container.

Ⅳ. Describe how to verify it

start a container, and list /etc

# pouch run -it --hostname helloPouch  reg.docker.alibaba-inc.com/busybox:latest sh


BusyBox v1.21.1 (Ubuntu 1:1.21.0-1ubuntu1) built-in shell (ash)
Enter 'help' for a list of built-in commands.

~ # ls /etc/
group          hosts          passwd
hostname       nsswitch.conf  resolv.conf

check network files

~ # cat /etc/hostname
helloPouch
~ # cat /etc/hosts
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
172.17.0.5	helloPouch
~ # ifconfig
eth0      Link encap:Ethernet  HWaddr 02:42:AC:11:00:05  
          inet addr:172.17.0.5  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::42:acff:fe11:5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:648 (648.0 B)  TX bytes:648 (648.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

~ # cat /etc/resolv.conf 
search DHCP
nameserver 127.0.0.11
options ndots:0

Ⅴ. Special notes for reviews

@codecov-io
Copy link

codecov-io commented May 25, 2018

Codecov Report

Merging #1403 into master will increase coverage by 20.93%.
The diff coverage is 43.67%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1403       +/-   ##
===========================================
+ Coverage   16.26%   37.19%   +20.93%     
===========================================
  Files         206      252       +46     
  Lines       13759    17545     +3786     
===========================================
+ Hits         2238     6526     +4288     
+ Misses      11365    10185     -1180     
- Partials      156      834      +678
Impacted Files Coverage Δ
cri/v1alpha2/cri_utils.go 28.35% <0%> (-0.07%) ⬇️
cli/common_flags.go 0% <0%> (ø) ⬆️
cli/container.go 0% <0%> (ø) ⬆️
cri/v1alpha1/cri_utils.go 29.25% <0%> (-0.07%) ⬇️
daemon/mgr/container.go 35.12% <45.16%> (+35.12%) ⬆️
daemon/mgr/spec_mount.go 72.61% <63.15%> (+72.61%) ⬆️
pkg/multierror/def.go 0% <0%> (-100%) ⬇️
cli/main.go 0% <0%> (ø) ⬆️
cli/pull.go 0% <0%> (ø) ⬆️
cli/upgrade.go 0% <0%> (ø) ⬆️
... and 129 more

@shaloulcy shaloulcy force-pushed the add_network_files branch from f76448c to e70ef26 Compare May 25, 2018 06:56
@allencloud
Copy link
Collaborator

I would like to invite @HusterWan to take a review of the design. I think adding network files into the container will make the usage inside our environment incompatible. Right?

@HusterWan
Copy link
Contributor

@allencloud Yes, we have discuss offline, i will review this PR

BTW, thanks a lot for your works @shaloulcy

return mounts
}

if c.HostnamePath != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

there are many duplicate codes here, maybe we can use

for _, bind := range []pathBinding{{Src: xxx, Dst: xxx}} {
}

WDYT? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree it


// isSetupNetworkMount checks whether set network mount.
func isSetupNetworkMount(mount *types.MountPoint, c *Container) bool {
if mount.Destination == "/etc/hostname" {
Copy link
Contributor

@HusterWan HusterWan May 29, 2018

Choose a reason for hiding this comment

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

How about code below ?

if utils.StringInSlice([]string{"/etc/hostname", "/etc/hosts", "/etc/resolv.conf", mount.Destination})
    xxx

the function just set one file, if user set all three files, should we also set them for c ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the outer function will iterator all mountpoints

@@ -69,6 +78,10 @@ func setupMounts(ctx context.Context, c *Container, s *specs.Spec) error {
Options: opts,
})
}

// generate network mounts.
Copy link
Contributor

@HusterWan HusterWan May 29, 2018

Choose a reason for hiding this comment

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

should we put check switch code in here?

if c.Config.DisableHostsfiles {
    mounts = append(mounts, generateNetworkMounts(c)...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree it

apis/swagger.yml Outdated
@@ -1787,6 +1787,11 @@ definitions:
type: "boolean"
x-nullable: false
default: true
DisableHostsfiles:
Copy link
Contributor

@HusterWan HusterWan May 29, 2018

Choose a reason for hiding this comment

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

Hostsfiles may not so good, do we have more properly name for /etc/hosts, /etc/hostname, /etc/resolve.conf files? 😆

cc @allencloud @rudyfly

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not like the naming of DisableHostsfiles , either. How about DisableLocalFiles or DisableNetworkFiles?

Copy link
Contributor

Choose a reason for hiding this comment

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

DisableNetworkFiles +1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree it

@shaloulcy shaloulcy force-pushed the add_network_files branch 2 times, most recently from 8888389 to 1f50786 Compare May 31, 2018 09:57
@shaloulcy shaloulcy requested a review from rudyfly May 31, 2018 10:04
@HusterWan
Copy link
Contributor

LGTM

BTW, can we add some test cases for this feature?

@pouchrobot pouchrobot added the LGTM one maintainer or community participant agrees to merge the pull reuqest. label May 31, 2018
@fuweid
Copy link
Contributor

fuweid commented May 31, 2018

@HusterWan I think we should add cases before merged. The test debt is rising right now... WDYT?

@HusterWan
Copy link
Contributor

@fuweid Yes, of course we should add test cases before merged this PR, take it easy dude ! 😆 😆

@fuweid
Copy link
Contributor

fuweid commented May 31, 2018

@HusterWan If the final can run into the Game7....yeah...of course!

@shaloulcy shaloulcy force-pushed the add_network_files branch from 1f50786 to 4d1f3c4 Compare May 31, 2018 13:17
Signed-off-by: Eric Li <lcy041536@gmail.com>
@shaloulcy
Copy link
Contributor Author

@fuweid @HusterWan I have add some test cases

}
container.NetworkSettings = new(types.NetworkSettings)
if len(config.NetworkingConfig.EndpointsConfig) > 0 {
container.NetworkSettings.Networks = config.NetworkingConfig.EndpointsConfig
}
if container.NetworkSettings.Networks == nil && networkMode != "" && !IsContainer(networkMode) {
if container.NetworkSettings.Networks == nil && !IsContainer(config.HostConfig.NetworkMode) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I found that here we have so much blocks about network handling in this Create function. And this make the code much much longer and a little bit difficult to read. Is there any way to encapsulate these blocks into a single function? @shaloulcy
Maybe in another pull request.

@HusterWan
Copy link
Contributor

@shaloulcy since the DisableNetworkFiles flag will affect all already running containers on host using PouchContainer in alibaba group, we must set DisableNetworkFiles to true before this feature releases online.

  • first, we stop pouchd
  • second, set all containers's DisableNetworkFiles to true by using script
  • then we start pouchd again

cc @yyb196


res.Assert(c, icmd.Success)
output := res.Stdout()
if strings.Contains(output, "hostname") {
Copy link
Contributor

Choose a reason for hiding this comment

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

we may make sure the test image never contains this three files, just comment.

@HusterWan HusterWan merged commit d41da05 into AliyunContainerService:master Jun 1, 2018
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] add domain name resolve for pouch container
6 participants