mirror of
https://github.com/containers/podman.git
synced 2025-06-30 07:26:39 +08:00
Only change network fields if they were actually changed by the user
Fixes: https://github.com/containers/podman/issues/13065 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
@ -103,6 +103,7 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
|
|||||||
opts = &entities.NetOptions{}
|
opts = &entities.NetOptions{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if flags.Changed("add-hosts") {
|
||||||
opts.AddHosts, err = flags.GetStringSlice("add-host")
|
opts.AddHosts, err = flags.GetStringSlice("add-host")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -113,7 +114,9 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.Changed("dns") {
|
||||||
servers, err := flags.GetStringSlice("dns")
|
servers, err := flags.GetStringSlice("dns")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -132,13 +135,17 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
|
|||||||
}
|
}
|
||||||
opts.DNSServers = append(opts.DNSServers, dns)
|
opts.DNSServers = append(opts.DNSServers, dns)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.Changed("dns-opt") {
|
||||||
options, err := flags.GetStringSlice("dns-opt")
|
options, err := flags.GetStringSlice("dns-opt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
opts.DNSOptions = options
|
opts.DNSOptions = options
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.Changed("dns-search") {
|
||||||
dnsSearches, err := flags.GetStringSlice("dns-search")
|
dnsSearches, err := flags.GetStringSlice("dns-search")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -156,7 +163,9 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
opts.DNSSearch = dnsSearches
|
opts.DNSSearch = dnsSearches
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.Changed("publish") {
|
||||||
inputPorts, err := flags.GetStringSlice("publish")
|
inputPorts, err := flags.GetStringSlice("publish")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -167,11 +176,14 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if flags.Changed("no-host") {
|
||||||
opts.NoHosts, err = flags.GetBool("no-hosts")
|
opts.NoHosts, err = flags.GetBool("no-hosts")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// parse the network only when network was changed
|
// parse the network only when network was changed
|
||||||
// otherwise we send default to server so that the server
|
// otherwise we send default to server so that the server
|
||||||
|
@ -589,4 +589,25 @@ load helpers
|
|||||||
run_podman network rm -t 0 -f $netname
|
run_podman network rm -t 0 -f $netname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "podman run CONTAINERS_CONF dns options" {
|
||||||
|
skip_if_remote "CONTAINERS_CONF redirect does not work on remote"
|
||||||
|
# Test on the CLI and via containers.conf
|
||||||
|
containersconf=$PODMAN_TMPDIR/containers.conf
|
||||||
|
|
||||||
|
searchIP="100.100.100.100"
|
||||||
|
cat >$containersconf <<EOF
|
||||||
|
[containers]
|
||||||
|
dns_searches = [ "example.com"]
|
||||||
|
dns_servers = [
|
||||||
|
"1.1.1.1",
|
||||||
|
"$searchIP",
|
||||||
|
"1.0.0.1",
|
||||||
|
"8.8.8.8",
|
||||||
|
]
|
||||||
|
EOF
|
||||||
|
CONTAINERS_CONF=$containersconf run_podman run --rm $IMAGE grep "example.com" /etc/resolv.conf
|
||||||
|
CONTAINERS_CONF=$containersconf run_podman run --rm $IMAGE grep $searchIP /etc/resolv.conf
|
||||||
|
is "$output" "nameserver $searchIP" "Should only be one $searchIP not multiple"
|
||||||
|
}
|
||||||
|
|
||||||
# vim: filetype=sh
|
# vim: filetype=sh
|
||||||
|
Reference in New Issue
Block a user