mirror of https://github.com/docker/cli.git
Merge pull request #3812 from mspiess/3293-fix-replicas-override-0
add ability to override ints in compose files with 0
This commit is contained in:
commit
37dcee37b6
|
@ -61,6 +61,7 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig,
|
||||||
reflect.TypeOf([]types.ServiceVolumeConfig{}): mergeSlice(toServiceVolumeConfigsMap, toServiceVolumeConfigsSlice),
|
reflect.TypeOf([]types.ServiceVolumeConfig{}): mergeSlice(toServiceVolumeConfigsMap, toServiceVolumeConfigsSlice),
|
||||||
reflect.TypeOf(types.ShellCommand{}): mergeShellCommand,
|
reflect.TypeOf(types.ShellCommand{}): mergeShellCommand,
|
||||||
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
|
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
|
||||||
|
reflect.PointerTo(reflect.TypeOf(uint64(1))): mergeUint64,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for name, overrideService := range overrideServices {
|
for name, overrideService := range overrideServices {
|
||||||
|
@ -259,6 +260,14 @@ func mergeServiceNetworkConfig(dst, src reflect.Value) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:unparam
|
||||||
|
func mergeUint64(dst, src reflect.Value) error {
|
||||||
|
if !src.IsNil() {
|
||||||
|
dst.Elem().Set(src.Elem())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func getLoggingDriver(v reflect.Value) string {
|
func getLoggingDriver(v reflect.Value) string {
|
||||||
return v.FieldByName("Driver").String()
|
return v.FieldByName("Driver").String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1237,3 +1237,60 @@ func TestMergeServiceNetworkConfig(t *testing.T) {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue #3293
|
||||||
|
func TestMergeServiceOverrideReplicasZero(t *testing.T) {
|
||||||
|
base := types.ServiceConfig{
|
||||||
|
Name: "someService",
|
||||||
|
Deploy: types.DeployConfig{
|
||||||
|
Replicas: uint64Ptr(3),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
override := types.ServiceConfig{
|
||||||
|
Name: "someService",
|
||||||
|
Deploy: types.DeployConfig{
|
||||||
|
Replicas: uint64Ptr(0),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
services, err := mergeServices([]types.ServiceConfig{base}, []types.ServiceConfig{override})
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, len(services), 1)
|
||||||
|
actual := services[0]
|
||||||
|
assert.DeepEqual(
|
||||||
|
t,
|
||||||
|
actual,
|
||||||
|
types.ServiceConfig{
|
||||||
|
Name: "someService",
|
||||||
|
Deploy: types.DeployConfig{
|
||||||
|
Replicas: uint64Ptr(0),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMergeServiceOverrideReplicasNotNil(t *testing.T) {
|
||||||
|
base := types.ServiceConfig{
|
||||||
|
Name: "someService",
|
||||||
|
Deploy: types.DeployConfig{
|
||||||
|
Replicas: uint64Ptr(3),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
override := types.ServiceConfig{
|
||||||
|
Name: "someService",
|
||||||
|
Deploy: types.DeployConfig{},
|
||||||
|
}
|
||||||
|
services, err := mergeServices([]types.ServiceConfig{base}, []types.ServiceConfig{override})
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, len(services), 1)
|
||||||
|
actual := services[0]
|
||||||
|
assert.DeepEqual(
|
||||||
|
t,
|
||||||
|
actual,
|
||||||
|
types.ServiceConfig{
|
||||||
|
Name: "someService",
|
||||||
|
Deploy: types.DeployConfig{
|
||||||
|
Replicas: uint64Ptr(3),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue