summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-01-31 09:58:15 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2022-02-02 10:28:34 -0500
commit4ddc4e79d73eea56929ed522f7d7fce6285a41d4 (patch)
treed54ad0421f17a9b52def033ed4d3bcffee387ac5 /cmd
parentdc0dc6a557dc9da9f89bd93baae3732e02b9ba20 (diff)
downloadpodman-4ddc4e79d73eea56929ed522f7d7fce6285a41d4.tar.gz
podman-4ddc4e79d73eea56929ed522f7d7fce6285a41d4.tar.bz2
podman-4ddc4e79d73eea56929ed522f7d7fce6285a41d4.zip
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>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/netflags.go110
1 files changed, 61 insertions, 49 deletions
diff --git a/cmd/podman/common/netflags.go b/cmd/podman/common/netflags.go
index 255996ac3..cfe4956b0 100644
--- a/cmd/podman/common/netflags.go
+++ b/cmd/podman/common/netflags.go
@@ -103,74 +103,86 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
opts = &entities.NetOptions{}
}
- opts.AddHosts, err = flags.GetStringSlice("add-host")
- if err != nil {
- return nil, err
- }
- // Verify the additional hosts are in correct format
- for _, host := range opts.AddHosts {
- if _, err := parse.ValidateExtraHost(host); err != nil {
+ if flags.Changed("add-hosts") {
+ opts.AddHosts, err = flags.GetStringSlice("add-host")
+ if err != nil {
return nil, err
}
+ // Verify the additional hosts are in correct format
+ for _, host := range opts.AddHosts {
+ if _, err := parse.ValidateExtraHost(host); err != nil {
+ return nil, err
+ }
+ }
}
- servers, err := flags.GetStringSlice("dns")
- if err != nil {
- return nil, err
- }
- for _, d := range servers {
- if d == "none" {
- opts.UseImageResolvConf = true
- if len(servers) > 1 {
- return nil, errors.Errorf("%s is not allowed to be specified with other DNS ip addresses", d)
- }
- break
+ if flags.Changed("dns") {
+ servers, err := flags.GetStringSlice("dns")
+ if err != nil {
+ return nil, err
}
- dns := net.ParseIP(d)
- if dns == nil {
- return nil, errors.Errorf("%s is not an ip address", d)
+ for _, d := range servers {
+ if d == "none" {
+ opts.UseImageResolvConf = true
+ if len(servers) > 1 {
+ return nil, errors.Errorf("%s is not allowed to be specified with other DNS ip addresses", d)
+ }
+ break
+ }
+ dns := net.ParseIP(d)
+ if dns == nil {
+ return nil, errors.Errorf("%s is not an ip address", d)
+ }
+ opts.DNSServers = append(opts.DNSServers, dns)
}
- opts.DNSServers = append(opts.DNSServers, dns)
}
- options, err := flags.GetStringSlice("dns-opt")
- if err != nil {
- return nil, err
+ if flags.Changed("dns-opt") {
+ options, err := flags.GetStringSlice("dns-opt")
+ if err != nil {
+ return nil, err
+ }
+ opts.DNSOptions = options
}
- opts.DNSOptions = options
- dnsSearches, err := flags.GetStringSlice("dns-search")
- if err != nil {
- return nil, err
- }
- // Validate domains are good
- for _, dom := range dnsSearches {
- if dom == "." {
- if len(dnsSearches) > 1 {
- return nil, errors.Errorf("cannot pass additional search domains when also specifying '.'")
- }
- continue
- }
- if _, err := parse.ValidateDomain(dom); err != nil {
+ if flags.Changed("dns-search") {
+ dnsSearches, err := flags.GetStringSlice("dns-search")
+ if err != nil {
return nil, err
}
+ // Validate domains are good
+ for _, dom := range dnsSearches {
+ if dom == "." {
+ if len(dnsSearches) > 1 {
+ return nil, errors.Errorf("cannot pass additional search domains when also specifying '.'")
+ }
+ continue
+ }
+ if _, err := parse.ValidateDomain(dom); err != nil {
+ return nil, err
+ }
+ }
+ opts.DNSSearch = dnsSearches
}
- opts.DNSSearch = dnsSearches
- inputPorts, err := flags.GetStringSlice("publish")
- if err != nil {
- return nil, err
- }
- if len(inputPorts) > 0 {
- opts.PublishPorts, err = specgenutil.CreatePortBindings(inputPorts)
+ if flags.Changed("publish") {
+ inputPorts, err := flags.GetStringSlice("publish")
if err != nil {
return nil, err
}
+ if len(inputPorts) > 0 {
+ opts.PublishPorts, err = specgenutil.CreatePortBindings(inputPorts)
+ if err != nil {
+ return nil, err
+ }
+ }
}
- opts.NoHosts, err = flags.GetBool("no-hosts")
- if err != nil {
- return nil, err
+ if flags.Changed("no-host") {
+ opts.NoHosts, err = flags.GetBool("no-hosts")
+ if err != nil {
+ return nil, err
+ }
}
// parse the network only when network was changed