-
Notifications
You must be signed in to change notification settings - Fork 225
libnetwork/etchosts: add host.containers.internal for machine #2464
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
Conversation
Reviewer's GuideAdds a one-time DNS lookup for host.containers.internal and plugs that lookup into GetHostContainersInternalIP so custom --add-host entries resolve correctly when running in a Podman machine with gvproxy. Sequence diagram for resolving host.containers.internal in Podman machinesequenceDiagram
participant User
participant Podman
participant etchosts
participant machine
participant net
User->>Podman: Run container with --add-host foobar:host-gateway
Podman->>etchosts: Call GetHostContainersInternalIP(opts)
etchosts->>machine: IsGvProxyBased()
alt machine is gvproxy-based
etchosts->>etchosts: machineHostContainersInternalIP()
etchosts->>net: LookupIP("host.containers.internal")
net-->>etchosts: IP address
etchosts-->>Podman: Return resolved IP
else not gvproxy-based
etchosts-->>Podman: Use default logic
end
Podman-->>User: /etc/hosts updated with correct IP
Class diagram for updated GetHostContainersInternalIP logicclassDiagram
class HostContainersInternalOptions {
Conf ConfType
PreferIP string
}
class ConfType {
Containers ContainersType
}
class ContainersType {
HostContainersInternalIP string
}
class machine {
+IsGvProxyBased() bool
}
class etchosts {
+GetHostContainersInternalIP(opts HostContainersInternalOptions) string
+machineHostContainersInternalIP() string
}
HostContainersInternalOptions --> ConfType : Conf
ConfType --> ContainersType : Containers
etchosts ..> machine : uses
etchosts ..> HostContainersInternalOptions : uses
etchosts ..> machineHostContainersInternalIP : calls
machineHostContainersInternalIP ..> net : LookupIP
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Luap99, sourcery-ai[bot] The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
LGTM, i assume there is no value in logging any errors there in the new function. |
I also could log it as warning so we see it in the journal if we ever have to ask users for logs it might be worth it. gvproxy should always resolve the name and we have the condition that checks that we are a gvproxy machine so I guess this never fails unless gvproxy is misbehaving. I think I need to update the docs here as well as we leaked some implementation details into them that now need to be updated. |
When running inside podman machine we cannot use the normal ip lookup logic for host.containers.internal because that should refer to the actual host system and not the VM ip. gvproxy already resolves the host.containers.internal name correctly but the issue is when a users wants to set a custom name via --add-host foobar:host-gateway then we need to know the actual ip to replace the host-gateway part. Right now we just always error which is not good. To fix this just look up the name ourselves so we can add it to /etc/hosts. Fixes: containers/podman#21681 Signed-off-by: Paul Holzinger <[email protected]>
|
LGTM |
|
@mheon PTAL (For reference I tested this change inside the machine and it worked as expected) |
|
/lgtm |
When running inside podman machine we cannot use the normal ip lookup logic for host.containers.internal because that should refer to the actual host system and not the VM ip.
gvproxy already resolves the host.containers.internal name correctly but the issue is when a users wants to set a custom name via --add-host foobar:host-gateway then we need to know the actual ip to replace the host-gateway part. Right now we just always error which is not good.
To fix this just look up the name ourselves so we can add it to /etc/hosts.
Fixes: containers/podman#21681
Summary by Sourcery
Resolve and cache the host.containers.internal address via DNS in Podman machine mode so that custom host-gateway mappings can be added to /etc/hosts without errors
New Features:
Bug Fixes:
Enhancements: