Skip to content

Commit

Permalink
fix network aliasses merge logic to conform to docker compose v1
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Dec 15, 2022
1 parent 999ce24 commit 615df13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 26 deletions.
15 changes: 0 additions & 15 deletions loader/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ var serviceSpecials = &specials{
reflect.TypeOf([]types.ServiceSecretConfig{}): mergeSlice(toServiceSecretConfigsMap, toServiceSecretConfigsSlice),
reflect.TypeOf([]types.ServiceConfigObjConfig{}): mergeSlice(toServiceConfigObjConfigsMap, toSServiceConfigObjConfigsSlice),
reflect.TypeOf(&types.UlimitsConfig{}): mergeUlimitsConfig,
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
},
}

Expand Down Expand Up @@ -327,20 +326,6 @@ func mergeUlimitsConfig(dst, src reflect.Value) error {
return nil
}

// nolint: unparam
func mergeServiceNetworkConfig(dst, src reflect.Value) error {
if src.Interface() != reflect.Zero(reflect.TypeOf(src.Interface())).Interface() {
dst.Elem().FieldByName("Aliases").Set(src.Elem().FieldByName("Aliases"))
if ipv4 := src.Elem().FieldByName("Ipv4Address").Interface().(string); ipv4 != "" {
dst.Elem().FieldByName("Ipv4Address").SetString(ipv4)
}
if ipv6 := src.Elem().FieldByName("Ipv6Address").Interface().(string); ipv6 != "" {
dst.Elem().FieldByName("Ipv6Address").SetString(ipv6)
}
}
return nil
}

func getLoggingDriver(v reflect.Value) string {
return v.FieldByName("Driver").String()
}
Expand Down
17 changes: 6 additions & 11 deletions loader/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ func TestLoadMultipleServiceNetworks(t *testing.T) {
},
expected: map[string]*types.ServiceNetworkConfig{
"net1": {
Aliases: []string{"alias2", "alias3"},
Aliases: []string{"alias1", "alias2", "alias3"},
},
"net2": nil,
"net3": {},
Expand Down Expand Up @@ -1111,13 +1111,8 @@ func TestMergeUlimitsConfig(t *testing.T) {
}

func TestMergeServiceNetworkConfig(t *testing.T) {
specials := &specials{
m: map[reflect.Type]func(dst, src reflect.Value) error{
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
},
}
base := map[string]*types.ServiceNetworkConfig{
"override-aliases": {
"merge": {
Aliases: []string{"100", "101"},
Ipv4Address: "127.0.0.1",
Ipv6Address: "0:0:0:0:0:0:0:1",
Expand All @@ -1129,7 +1124,7 @@ func TestMergeServiceNetworkConfig(t *testing.T) {
},
}
override := map[string]*types.ServiceNetworkConfig{
"override-aliases": {
"merge": {
Aliases: []string{"110", "111"},
Ipv4Address: "127.0.1.1",
Ipv6Address: "0:0:0:0:0:0:1:1",
Expand All @@ -1140,14 +1135,14 @@ func TestMergeServiceNetworkConfig(t *testing.T) {
Ipv6Address: "0:0:0:0:0:0:3:1",
},
}
err := mergo.Merge(&base, &override, mergo.WithOverride, mergo.WithTransformers(specials))
err := mergo.Merge(&base, &override, mergo.WithAppendSlice, mergo.WithOverride)
assert.NilError(t, err)
assert.DeepEqual(
t,
base,
map[string]*types.ServiceNetworkConfig{
"override-aliases": {
Aliases: []string{"110", "111"},
"merge": {
Aliases: []string{"100", "101", "110", "111"},
Ipv4Address: "127.0.1.1",
Ipv6Address: "0:0:0:0:0:0:1:1",
},
Expand Down

0 comments on commit 615df13

Please sign in to comment.