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 --hosts-file flag; Add nohosts to remote build APIs #21062

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

gavinkflam
Copy link
Contributor

@gavinkflam gavinkflam commented Dec 20, 2023

I added a container level base-hosts-file configuration in #21013. This PR allows user to apply this configuration using a CLI flag. cc @Luap99

This is intended to be a container / pod level override of base_hosts_file in containers.conf. https://github.com/containers/common/blob/main/docs/containers.conf.5.md#containers-table

Closes #13277

Does this PR introduce a user-facing change?

Add --hosts-file flag to container create, container run, and pod create
Add nohosts option to /build and /libpod/build

@gavinkflam gavinkflam force-pushed the base-hosts-file-flag branch 2 times, most recently from 8549fcb to d4afcbb Compare December 20, 2023 17:17
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 23, 2023
@gavinkflam
Copy link
Contributor Author

gavinkflam commented Dec 27, 2023

Hi @rhatdan, thank you for reviewing the changes.

My idea is to provide a container and pod level override in base_hosts_file of containers.conf, which is currently defaulted to the host's /etc/hosts. I agree --no-hosts seems redundant with the introduction of this new flag. I can hide it if you think that is appropriate.

Flag Container hosts file
--base-hosts-file="" Entries in base_hosts_file of containers.conf + Podman managed entries
--base-hosts-file="/path/to/hosts" Entries in /path/to/hosts + Podman managed entries
--base-hosts-file="image" Entries in the image's /etc/hosts + Podman managed entries
--base-hosts-file="none" Use only Podman managed entries
--no-hosts Use the image /etc/hosts without adding any entries

The current --no-hosts flag is similar to --base-hosts-file="image" with a subtle difference that --no-hosts doesn't add Podman managed entries. They include container name, add_hosts in containers.conf, network host entries, pasta IP, etc.

return etchosts.New(&etchosts.Params{
BaseFile: baseHostFile,
ExtraHosts: c.config.HostAdd,
ContainerIPs: containerIPsEntries,
HostContainersInternalIP: etchosts.GetHostContainersInternalIP(c.runtime.config, c.state.NetworkStatus, c.runtime.network),
TargetFile: targetFile,
})

Do you think this fits into the wider Podman design and roadmap? I am open to changing anything or even starting from scratch.

@rhatdan
Copy link
Member

rhatdan commented Dec 27, 2023

I am fine with this, but I do not think base- adds anything to my understanding. If we can find a way to eliminate --no-host at all and do

--hosts-file="null" Use only Podman managed entries
--hosts-file="none" Use the image /etc/hosts without adding any entries (--no-hosts)

Bottom line for me is discoverability for these. Having them all named and documented in the man page together would help users figure out which is best for them.

Having a random --no-hosts someone else in the man page, does not help with this.

Better names/descriptions are always welcome.

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.

--no-hosts is a well known docker option so we should not remove it from the docs and this option does not replace this option at all.

We should make the connection between the two options clear int he man page, i.e. --no-hosts should link to --hosts-file and the other way around.

cmd/podman/common/completion.go Outdated Show resolved Hide resolved
cmd/podman/common/netflags.go Outdated Show resolved Hide resolved
docs/source/markdown/options/base-hosts-file.md Outdated Show resolved Hide resolved
test/e2e/run_test.go Outdated Show resolved Hide resolved
@gavinkflam
Copy link
Contributor Author

@rhatdan @Luap99 Sounds like we have two directions here.

  1. Bring together --no-hosts and this new flag, and introduce a new mode to use only Podman managed entries.
  2. Keep it as an override of base_hosts_file in containers.conf.

I'm leaning towards (2) since we have a configuration item in containers.conf already. What do you think?

@Luap99
Copy link
Member

Luap99 commented Jan 4, 2024

I say we should do 2

@rhatdan
Copy link
Member

rhatdan commented Jan 4, 2024

Since docker supports the --no-host, then go with 2

Copy link

github-actions bot commented Feb 6, 2024

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

@rhatdan
Copy link
Member

rhatdan commented Feb 7, 2024

@gavinkflam Still working on this?

@gavinkflam
Copy link
Contributor Author

Yes. I'll find some time to wrap up the changes. Thanks.

@gavinkflam
Copy link
Contributor Author

@rhatdan @Luap99 This is now complete. Apologies for the delay - it's been an eventful year, and I lost track of this open PR.

@gavinkflam gavinkflam changed the title Add --base-hosts-file flag Add --hosts-file flag Nov 11, 2024
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.

Thanks mostly looks good but I think we can do a bit better on the tests

docs/source/markdown/options/hosts-file.md Outdated Show resolved Hide resolved
cmd/podman/common/completion.go Outdated Show resolved Hide resolved
test/e2e/containers_conf_test.go Outdated Show resolved Hide resolved
test/e2e/containers_conf_test.go Outdated Show resolved Hide resolved
@gavinkflam gavinkflam force-pushed the base-hosts-file-flag branch 2 times, most recently from 451a94e to 4b70680 Compare November 17, 2024 06:39
@github-actions github-actions bot added the kind/api-change Change to remote API; merits scrutiny label Nov 17, 2024
@gavinkflam
Copy link
Contributor Author

gavinkflam commented Nov 17, 2024

Thanks mostly looks good but I think we can do a bit better on the tests

Thank you for the suggestions, @Luap99! I’ve enhanced the tests and implemented the flag for pod create. The pod create command now uses this flag to configure the infra-container appropriately. Additionally, I’ve renamed the container BaseHostsFile to HostsFile for better naming consistency.

During testing, I discovered that image builds using the --no-hosts flag were failing in remote tests. I realized that this flag was never supported in the remote build APIs. To address this, I’ve added a nohosts option to the build APIs.

@gavinkflam gavinkflam changed the title Add --hosts-file flag Add --hosts-file flag; Add nohosts to remote build APIs Nov 17, 2024
@gavinkflam gavinkflam requested a review from Luap99 November 17, 2024 18:33
libpod/container_config.go Outdated Show resolved Hide resolved
pkg/specgen/specgen.go Outdated Show resolved Hide resolved
@gavinkflam gavinkflam requested a review from Luap99 November 18, 2024 17:05
@gavinkflam
Copy link
Contributor Author

Reverted rename and rebased.

* Add --hosts-file flag to container create, container run and pod create
* Add HostsFile field to pod inspect and container inspect results
* Test BaseHostsFile config in containers.conf

Signed-off-by: Gavin Lam <[email protected]>
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.

LGTM
Thank you

Copy link
Contributor

openshift-ci bot commented Nov 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gavinkflam, Luap99, 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

@gavinkflam
Copy link
Contributor Author

/packit retest-failed

@rhatdan rhatdan removed the stale-pr label Nov 25, 2024
@rhatdan
Copy link
Member

rhatdan commented Nov 25, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 25, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 70c2559 into containers:main Nov 25, 2024
79 of 80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/api-change Change to remote API; merits scrutiny lgtm Indicates that a PR is ready to be merged. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

host.containers.internal is inconsistent for rootful containers assigned to a pod and not
3 participants