-
Notifications
You must be signed in to change notification settings - Fork 950
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
feature: add container's network files #1403
Conversation
edf5302
to
f76448c
Compare
Codecov Report
@@ 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
|
f76448c
to
e70ef26
Compare
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? |
@allencloud Yes, we have discuss offline, i will review this PR BTW, thanks a lot for your works @shaloulcy |
e70ef26
to
21470b4
Compare
daemon/mgr/spec_mount.go
Outdated
return mounts | ||
} | ||
|
||
if c.HostnamePath != "" { |
There was a problem hiding this comment.
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? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree it
daemon/mgr/spec_mount.go
Outdated
|
||
// isSetupNetworkMount checks whether set network mount. | ||
func isSetupNetworkMount(mount *types.MountPoint, c *Container) bool { | ||
if mount.Destination == "/etc/hostname" { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
daemon/mgr/spec_mount.go
Outdated
@@ -69,6 +78,10 @@ func setupMounts(ctx context.Context, c *Container, s *specs.Spec) error { | |||
Options: opts, | |||
}) | |||
} | |||
|
|||
// generate network mounts. |
There was a problem hiding this comment.
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)...)
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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? 😆
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DisableNetworkFiles +1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree it
8888389
to
1f50786
Compare
LGTM BTW, can we add some test cases for this feature? |
@HusterWan I think we should add cases before merged. The test debt is rising right now... WDYT? |
@fuweid Yes, of course we should add test cases before merged this PR, take it easy dude ! 😆 😆 |
@HusterWan If the final can run into the Game7....yeah...of course! |
1f50786
to
4d1f3c4
Compare
Signed-off-by: Eric Li <lcy041536@gmail.com>
4d1f3c4
to
db46eff
Compare
@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) { |
There was a problem hiding this comment.
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.
@shaloulcy since the
cc @yyb196 |
|
||
res.Assert(c, icmd.Success) | ||
output := res.Stdout() | ||
if strings.Contains(output, "hostname") { |
There was a problem hiding this comment.
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.
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
check network files
Ⅴ. Special notes for reviews