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

[WIP] Return slirp ip information from getHosts() #13219

Closed
wants to merge 1 commit into from

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Feb 11, 2022

When one container shares the network namespace with another container
or with a Pod, there should be an entry added to the /etc/hosts file
for the second container.

Fixes: #12003

Signed-off-by: Daniel J Walsh [email protected]

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 11, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Feb 11, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 11, 2022
@rhatdan
Copy link
Member Author

rhatdan commented Feb 11, 2022

@Luap99 PTAL, I have added comment directed at you on why this is not working for rootfull containers.

Basically the tests is

# podman run -d --name test1 alpine top
# podman run --net=container:test1 --name test2 alpine cat /etc/hosts

And user expects to see test2 and test1 listed in /etc/hosts.

@@ -2397,7 +2407,7 @@ func (c *Container) getHosts() string {
// if no bridge gw was found try to use a local ip
if host == "" {
if ip := getLocalIP(); ip != "" {
host = fmt.Sprintf("%s\t%s\n", ip, "host.containers.internal")
host = fmt.Sprintf("%s\t%s %s\n", ip, c.Hostname(), c.config.Name)
Copy link
Member

Choose a reason for hiding this comment

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

This should not be changed we add host.containers.internal here

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I will remove it, but I think it ends up being added multiple times in certain situations. Bottom line is this does not work in rootfull mode. And I am not sure why.

Comment on lines +2380 to +2387
if depCtr.config.NetMode.IsSlirp4netns() {
// When using slirp4netns, the interface gets a static IP
if slirp4netnsIP, err := GetSlirp4netnsIP(depCtr.slirp4netnsSubnet); err != nil {
logrus.Warnf("Failed to determine slirp4netnsIP: %v", err.Error())
} else {
return fmt.Sprintf("%s\t%s %s\n", slirp4netnsIP.String(), c.Hostname(), c.config.Name)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This block has to be moved to line 2318, you are changing the host.containers.internal code here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not find the depCtr until now.

outer:
// Paul this is returning nothing, even though I know depctr is up and
// running with an IP Address in rootfull mode?
Copy link
Member

Choose a reason for hiding this comment

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

I think you want to change c.cniHosts() and not the code here

Copy link
Member Author

Choose a reason for hiding this comment

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

Fine, how do I change it. It looks like depctr has no network in rootfull mode.

Copy link
Member

Choose a reason for hiding this comment

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

seems to work for me, what are you expecting?
This code is for host.containers.internal, if you want to add the container/host names you need to do this at a different place before this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Where would you suggest?

When one container shares the network namespace with another container
or with a Pod, there should be an entry added to the /etc/hosts file
for the second container.

Fixes: containers#12003

Signed-off-by: Daniel J Walsh <[email protected]>
@vrothberg
Copy link
Member

Friendly ping. @rhatdan, do you still want this in?

@Luap99
Copy link
Member

Luap99 commented Apr 6, 2022

No this should be part of my /etc/hosts rewrite for c/common

@Luap99 Luap99 closed this Apr 6, 2022
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression 3.4: missing entries in /etc/hosts
3 participants