Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 74cf58c

Browse files
authored
Merge pull request #1967 from thaJeztah/19.03_backport_fix_advanced_options_for_backward_compat
[19.03 backport] Fix advanced options for backward compatibility Upstream-commit: 2f1931f9eb2d6bac2efd48d94739f2e9919d4d7d Component: cli
2 parents 6d9535d + b9135b2 commit 74cf58c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

components/cli/cli/command/container/opts.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io/ioutil"
88
"path"
9+
"reflect"
910
"regexp"
1011
"strconv"
1112
"strings"
@@ -707,6 +708,15 @@ func parseNetworkOpts(copts *containerOptions) (map[string]*networktypes.Endpoin
707708
if _, ok := endpoints[n.Target]; ok {
708709
return nil, errdefs.InvalidParameter(errors.Errorf("network %q is specified multiple times", n.Target))
709710
}
711+
712+
// For backward compatibility: if no custom options are provided for the network,
713+
// and only a single network is specified, omit the endpoint-configuration
714+
// on the client (the daemon will still create it when creating the container)
715+
if i == 0 && len(copts.netMode.Value()) == 1 {
716+
if ep == nil || reflect.DeepEqual(*ep, networktypes.EndpointSettings{}) {
717+
continue
718+
}
719+
}
710720
endpoints[n.Target] = ep
711721
}
712722
if hasUserDefined && hasNonUserDefined {

components/cli/cli/command/container/opts_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,13 @@ func TestParseNetworkConfig(t *testing.T) {
401401
{
402402
name: "single-network-legacy",
403403
flags: []string{"--network", "net1"},
404-
expected: map[string]*networktypes.EndpointSettings{"net1": {}},
404+
expected: map[string]*networktypes.EndpointSettings{},
405405
expectedCfg: container.HostConfig{NetworkMode: "net1"},
406406
},
407407
{
408408
name: "single-network-advanced",
409409
flags: []string{"--network", "name=net1"},
410-
expected: map[string]*networktypes.EndpointSettings{"net1": {}},
410+
expected: map[string]*networktypes.EndpointSettings{},
411411
expectedCfg: container.HostConfig{NetworkMode: "net1"},
412412
},
413413
{

0 commit comments

Comments
 (0)