Documentation ¶
Index ¶
- func Add(file string, entries HostEntries) error
- func AddIfExists(file string, existsEntries, newEntries HostEntries) error
- func GetBaseHostFile(confValue, imageRoot string) (string, error)
- func GetHostContainersInternalIP(conf *config.Config, netStatus map[string]types.StatusBlock, ...) string
- func New(params *Params) error
- func Remove(file string, entries HostEntries) error
- type HostEntries
- type HostEntry
- type Params
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add(file string, entries HostEntries) error
Add adds the given entries to the hosts file, entries are only added if they are not already present. Add is not atomic because it will keep the current file inode. This is required to keep bind mounts for containers working.
func AddIfExists ¶
func AddIfExists(file string, existsEntries, newEntries HostEntries) error
AddIfExists will add the given entries only if one of the existsEntries is in the hosts file. This API is required for podman network connect. Since we want to add the same host name for each network ip we want to add duplicates and the normal Add() call prevents us from doing so. However since we also do not want to overwrite potential entries that were added by users manually we first have to check if there are the current expected entries in the file. Note that this will only check for one match not all. It will also only check that the ip and one of the hostnames match like Remove().
func GetBaseHostFile ¶
GetBaseHostFile return the hosts file which should be used as base. The first param should be the config value config.Containers.BaseHostsFile The second param should be the root path to the mounted image. This is required when the user conf value is set to "image".
func GetHostContainersInternalIP ¶
func GetHostContainersInternalIP(conf *config.Config, netStatus map[string]types.StatusBlock, networkInterface types.ContainerNetwork) string
GetHostContainersInternalIP return the host.containers.internal ip if netStatus is not nil then networkInterface also must be non nil otherwise this function panics
func New ¶
New will create a new hosts file and write this to the target file. This function does not prevent any kind of concurrency problems, it is the callers responsibility to avoid concurrent writes to this file. The extraHosts are written first, then the hosts from the file baseFile and the containerIps. The container ip entry is only added when the name was not already added before.
func Remove ¶
func Remove(file string, entries HostEntries) error
Remove will remove the given entries from the file. An entry will be removed when the ip and at least one name matches. Not all names have to match. If the given entries are not present in the file no error is returned. Remove is not atomic because it will keep the current file inode. This is required to keep bind mounts for containers working.
Types ¶
type HostEntries ¶
type HostEntries []HostEntry
func GetNetworkHostEntries ¶
func GetNetworkHostEntries(netStatus map[string]types.StatusBlock, names ...string) HostEntries
GetNetworkHostEntries returns HostEntries for all ips in the network status with the given hostnames.
type Params ¶
type Params struct { // BaseFile is the file where we read entries from and add entries to // the target hosts file. If the name is empty it will not read any entries. BaseFile string // ExtraHosts is a slice of entries in the "hostname:ip" format. // Optional. ExtraHosts []string // ContainerIPs should contain the main container ipv4 and ipv6 if available // with the container name and host name as names set. // Optional. ContainerIPs HostEntries // HostContainersInternalIP is the IP for the host.containers.internal entry. // Optional. HostContainersInternalIP string // TargetFile where the hosts are written to. TargetFile string }
Params for the New() function call