Skip to content

Commit

Permalink
Added transforms for compose overrides
Browse files Browse the repository at this point in the history
Added transforms for when merging compose overrides to preserve the
functionality that was broken by bumping mergo to v0.3.8.

This includes:
- Special transform for ulimits so single overrides both soft/hard and
the reverse
- Special transform for service network configs so the override replaces
all aliases

Signed-off-by: Nick Adcock <[email protected]>
  • Loading branch information
zappy-shu committed Jan 21, 2020
1 parent 6cf7970 commit f8c1131
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cli/compose/loader/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig,
reflect.TypeOf([]types.ServicePortConfig{}): mergeSlice(toServicePortConfigsMap, toServicePortConfigsSlice),
reflect.TypeOf([]types.ServiceSecretConfig{}): mergeSlice(toServiceSecretConfigsMap, toServiceSecretConfigsSlice),
reflect.TypeOf([]types.ServiceConfigObjConfig{}): mergeSlice(toServiceConfigObjConfigsMap, toSServiceConfigObjConfigsSlice),
reflect.TypeOf(&types.UlimitsConfig{}): mergeUlimitsConfig,
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
},
}
for name, overrideService := range overrideServices {
Expand Down Expand Up @@ -201,6 +203,28 @@ func mergeLoggingConfig(dst, src reflect.Value) error {
return nil
}

//nolint: unparam
func mergeUlimitsConfig(dst, src reflect.Value) error {
if src.Interface() != reflect.Zero(reflect.TypeOf(src.Interface())).Interface() {
dst.Elem().Set(src.Elem())
}
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

0 comments on commit f8c1131

Please sign in to comment.