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

Add support for special IP designator host-gateway in --add-hosts. #14392

Closed

Conversation

willmtemple
Copy link

Implements the behavior described in #14390 (feature request).

host-gateway is a special designator used in the IP address position of --add-host entries. It maps to the container's host.containers.internal IP address. moby-engine/docker CLI implement this same option.

This implementation:

  • Allows the string "<hostname>:host-gateway" as a valid host entry (it is carried through all options that derive from the NetOptions.AddHosts field).
  • Replaces host entries that are mapped to "host-gateway" with the container's host.containers.internal IP address during etchosts construction in the linux libpod container driver.

Signed-off-by: Will Temple [email protected]

Closes #14390

Example:

$ bin/podman run -it --rm --add-host testhostname:host-gateway alpine   
/ # cat /etc/hosts
192.168.1.228   testhostname
127.0.0.1       localhost
::1     localhost
192.168.1.228   host.containers.internal
10.0.2.100      1b6fcb8904fe vibrant_wescoff
/ # ping testhostname
PING testhostname (192.168.1.228): 56 data bytes
64 bytes from 192.168.1.228: seq=0 ttl=42 time=0.135 ms

Does this PR introduce a user-facing change?

Is this what your CI is expecting?

Adds support for the special string `host-gateway` as an "IP address" when using the `--add-host` command-line flag. A mapping to "host-gateway" results in the given hostname being mapped to the host IP address (the same IP as for the default `host.containers.internal` address) in the `/etc/hosts` file within the container.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented May 26, 2022

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: willmtemple
To complete the pull request process, please assign zhangguanzhang after the PR has been reviewed.
You can assign the PR to them by writing /assign @zhangguanzhang in a comment when ready.

The full list of commands accepted by this bot can be found 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

Signed-off-by: Will Temple <[email protected]>
@@ -54,6 +54,9 @@ func ValidateExtraHost(val string) (string, error) { // nolint
if len(arr) != 2 || len(arr[0]) == 0 {
return "", fmt.Errorf("bad format for add-host: %q", val)
}
if (arr[1] == "host-gateway") {
return val, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Could you update the function comment please to cover this new case?

@rhatdan
Copy link
Member

rhatdan commented May 28, 2022

@Luap99 PTAL

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

This has to be fixed in the etchosts package instead of this workaround in libpod. Otherwise it will not work for podman build.

@willmtemple
Copy link
Author

@Luap99 Do you think it's sufficient to just allow passing host-gateway as an IP string to libnetwork/etchosts? We could just do the conversion to the host's interface IP there instead of here if it's okay for the host-gateway string to flow through the rest of the pod creation pipeline.

@Luap99
Copy link
Member

Luap99 commented Jun 2, 2022

@Luap99 Do you think it's sufficient to just allow passing host-gateway as an IP string to libnetwork/etchosts? We could just do the conversion to the host's interface IP there instead of here if it's okay for the host-gateway string to flow through the rest of the pod creation pipeline.

Yes that is what I had in mind.

@rhatdan
Copy link
Member

rhatdan commented Jun 21, 2022

@willmtemple @Luap99 what is going on with this PR?

@github-actions
Copy link

A friendly reminder that this PR had no activity for 30 days.

@rhatdan
Copy link
Member

rhatdan commented Jul 25, 2022

@Luap99 Update?

@github-actions github-actions bot removed the stale-pr label Jul 26, 2022
@github-actions
Copy link

A friendly reminder that this PR had no activity for 30 days.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 6, 2022
@openshift-merge-robot
Copy link
Collaborator

@willmtemple: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@vrothberg
Copy link
Member

The PR looks abandoned. Please re-open when you find time to get back to it.

@vrothberg vrothberg closed this Jan 17, 2023
@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 14, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note stale-pr
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support special IP designator host-gateway in --add-host.
6 participants