Add support for the new c/common pasta options
We always map 169.254.1.2 with pasta to the host now so ensure the host.containers.internal entry is set correctly. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
7bf7da57ad
commit
5184bf1612
11
run.go
11
run.go
|
@ -222,9 +222,10 @@ type IDMaps struct {
|
|||
|
||||
// netResult type to hold network info for hosts/resolv.conf
|
||||
type netResult struct {
|
||||
entries etchosts.HostEntries
|
||||
dnsServers []string
|
||||
excludeIPs []net.IP
|
||||
ipv6 bool
|
||||
keepHostResolvers bool
|
||||
entries etchosts.HostEntries
|
||||
dnsServers []string
|
||||
excludeIPs []net.IP
|
||||
ipv6 bool
|
||||
keepHostResolvers bool
|
||||
preferredHostContainersInternalIP string
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ func (b *Builder) createHostsFile(rdir string, chownOpts *idtools.IDPair) (strin
|
|||
return targetfile, nil
|
||||
}
|
||||
|
||||
func (b *Builder) addHostsEntries(file, imageRoot string, entries etchosts.HostEntries, exculde []net.IP) error {
|
||||
func (b *Builder) addHostsEntries(file, imageRoot string, entries etchosts.HostEntries, exclude []net.IP, preferIP string) error {
|
||||
conf, err := config.Default()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -163,11 +163,15 @@ func (b *Builder) addHostsEntries(file, imageRoot string, entries etchosts.HostE
|
|||
return err
|
||||
}
|
||||
return etchosts.New(&etchosts.Params{
|
||||
BaseFile: base,
|
||||
ExtraHosts: b.CommonBuildOpts.AddHost,
|
||||
HostContainersInternalIP: etchosts.GetHostContainersInternalIPExcluding(conf, nil, nil, exculde),
|
||||
TargetFile: file,
|
||||
ContainerIPs: entries,
|
||||
BaseFile: base,
|
||||
ExtraHosts: b.CommonBuildOpts.AddHost,
|
||||
HostContainersInternalIP: etchosts.GetHostContainersInternalIP(etchosts.HostContainersInternalOptions{
|
||||
Conf: conf,
|
||||
Exclude: exclude,
|
||||
PreferIP: preferIP,
|
||||
}),
|
||||
TargetFile: file,
|
||||
ContainerIPs: entries,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1255,7 +1259,7 @@ func (b *Builder) runUsingRuntimeSubproc(isolation define.Isolation, options Run
|
|||
|
||||
// only add hosts if we manage the hosts file
|
||||
if hostsFile != "" {
|
||||
err = b.addHostsEntries(hostsFile, rootPath, netResult.entries, netResult.excludeIPs)
|
||||
err = b.addHostsEntries(hostsFile, rootPath, netResult.entries, netResult.excludeIPs, netResult.preferredHostContainersInternalIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -223,7 +223,7 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
|||
})
|
||||
}
|
||||
}
|
||||
err = b.addHostsEntries(hostsFile, mountPoint, entries, nil)
|
||||
err = b.addHostsEntries(hostsFile, mountPoint, entries, nil, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
20
run_linux.go
20
run_linux.go
|
@ -393,7 +393,7 @@ func (b *Builder) Run(command []string, options RunOptions) error {
|
|||
})
|
||||
}
|
||||
}
|
||||
err = b.addHostsEntries(hostsFile, mountPoint, entries, nil)
|
||||
err = b.addHostsEntries(hostsFile, mountPoint, entries, nil, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -652,7 +652,7 @@ func setupSlirp4netnsNetwork(config *config.Config, netns, cid string, options,
|
|||
}
|
||||
|
||||
func setupPasta(config *config.Config, netns string, options, hostnames []string) (func(), *netResult, error) {
|
||||
res, err := pasta.Setup2(&pasta.SetupOptions{
|
||||
res, err := pasta.Setup(&pasta.SetupOptions{
|
||||
Config: config,
|
||||
Netns: netns,
|
||||
ExtraOptions: options,
|
||||
|
@ -666,12 +666,18 @@ func setupPasta(config *config.Config, netns string, options, hostnames []string
|
|||
entries = etchosts.HostEntries{{IP: res.IPAddresses[0].String(), Names: hostnames}}
|
||||
}
|
||||
|
||||
mappedIP := ""
|
||||
if len(res.MapGuestAddrIPs) > 0 {
|
||||
mappedIP = res.MapGuestAddrIPs[0]
|
||||
}
|
||||
|
||||
result := &netResult{
|
||||
entries: entries,
|
||||
dnsServers: res.DNSForwardIPs,
|
||||
excludeIPs: res.IPAddresses,
|
||||
ipv6: res.IPv6,
|
||||
keepHostResolvers: true,
|
||||
entries: entries,
|
||||
dnsServers: res.DNSForwardIPs,
|
||||
excludeIPs: res.IPAddresses,
|
||||
ipv6: res.IPv6,
|
||||
keepHostResolvers: true,
|
||||
preferredHostContainersInternalIP: mappedIP,
|
||||
}
|
||||
|
||||
return nil, result, nil
|
||||
|
|
|
@ -742,6 +742,8 @@ function configure_and_check_user() {
|
|||
ip=$(hostname -I | cut -f 1 -d " ")
|
||||
run_buildah run --network pasta --hostname $hostname $cid cat /etc/hosts
|
||||
assert "$output" =~ "$ip[[:blank:]]$hostname $cid" "--network pasta adds correct hostname"
|
||||
# FIXME we need pasta 20240814 or newer in the VMs to enable this
|
||||
# assert "$output" =~ "169.254.1.2[[:blank:]]host.containers.internal" "--network pasta adds correct internal entry"
|
||||
|
||||
# check with containers.conf setting
|
||||
echo -e "[network]\ndefault_rootless_network_cmd = \"pasta\"" > ${TEST_SCRATCH_DIR}/containers.conf
|
||||
|
@ -750,7 +752,7 @@ function configure_and_check_user() {
|
|||
|
||||
# resolv.conf checks
|
||||
run_buildah run --network pasta $cid grep nameserver /etc/resolv.conf
|
||||
assert "${lines[0]}" == "nameserver 169.254.0.1" "first pasta nameserver should be stub forwarder"
|
||||
assert "${lines[0]}" == "nameserver 169.254.1.1" "first pasta nameserver should be stub forwarder"
|
||||
|
||||
run_buildah run --network pasta:--dns-forward,192.168.0.1 $cid grep nameserver /etc/resolv.conf
|
||||
assert "${lines[0]}" == "nameserver 192.168.0.1" "pasta nameserver with --dns-forward"
|
||||
|
|
Loading…
Reference in New Issue