keep pod hostname when a container is stopped#28494
keep pod hostname when a container is stopped#28494agp8x wants to merge 1 commit intocontainers:mainfrom
Conversation
Signed-off-by: agp8x <git@agp8x.org>
Luap99
left a comment
There was a problem hiding this comment.
Thanks, we need a test case at least.
But I don't believe fixing this like that is correct, you have just sidestep your personal problem. If a user would have the container name and ip in the hosts file it would still be the same problem.
Isn't the real problem that the etchosts.Remove() only matches one name instead of matching all names? I guess this is because Add() does not actually add all names when the hostname or container name is already present.
Since the main pod infra will always have the hostname as entry with the main ip the localhost entries for the container will never receive the hostname and thus we cannot use the full match like that.
But then if we never add the hostname in the entry that we might as well just drop it from getLocalhostHostEntry() and then it would work already for you?
Practically there is the question of why do you even set --add-host hostname:127.0.0.1 when there is a hostname entry by default?
| return etchosts.HostEntries{{IP: "127.0.0.1", Names: []string{c.Hostname(), c.config.Name}}} | ||
| } | ||
|
|
||
| func getContainerNameHostEntry(c *Container) etchosts.HostEntries { |
There was a problem hiding this comment.
This name makes no sense, it is trival to misuse such a function based on that name. Since it is supposed to match the other one it should be named like that and then it needs a big comment why this exists and is different.
I have applications running in multiple pods that need a FQDN, so the --hostname argument is not sufficient. To get the FQDN for the pod hostname, there has to be an entry
That sounds great, I'll add a test case and refactor it. |
Checklist
Ensure you have completed the following checklist for your pull request to be reviewed:
commits. (
git commit -s). (If needed, usegit commit -s --amend). The author email must matchthe sign-off email address. See CONTRIBUTING.md
for more information.
Fixes: #00000in commit message (if applicable)make validatepr(format/lint checks)Noneif no user-facing changes)Does this PR introduce a user-facing change?
Problem
When a Pod is configured with additional hosts containing an FQDN for the pod hostname, the FQDN entry is removed when any container is stopped.
Root Cause
etchosts.Remove()is called with an array containing the container hostname. In Pods, the container hostname is configured on pod level.Fix
Omit the hostname during remove
Test
Preparations
mkdir -p /my/run/Create pod
Start containers
Verify
podman exec my-pod-contA hostname -f->myhost--my-pod.my.domainpodman stop my-pod-contBpodman exec my-pod-contA hostname -f->hostname: myhost--my-pod: Host not found