Skip to content

Commit 880fee7

Browse files
committed
revert implicit deletion of disappeared optional slice
1 parent f0fe206 commit 880fee7

4 files changed

Lines changed: 59 additions & 48 deletions

File tree

rollout/executor_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,22 @@ func TestExecutor_Rollout(t *testing.T) {
9999
taskMock.EXPECT().Wait(gomock.Any()).Return(nil),
100100
ecsMock.EXPECT().UpdateService(gomock.Any(), &ecs.UpdateServiceInput{
101101
Cluster: &envars.Cluster,
102-
CapacityProviderStrategy: []ecstypes.CapacityProviderStrategyItem{},
102+
CapacityProviderStrategy: envars.ServiceDefinitionInput.CapacityProviderStrategy,
103103
Service: &envars.Service,
104104
TaskDefinition: td.TaskDefinitionArn,
105105
ServiceConnectConfiguration: envars.ServiceDefinitionInput.ServiceConnectConfiguration,
106106
LoadBalancers: envars.ServiceDefinitionInput.LoadBalancers,
107107
NetworkConfiguration: envars.ServiceDefinitionInput.NetworkConfiguration,
108108
PlatformVersion: envars.ServiceDefinitionInput.PlatformVersion,
109-
VolumeConfigurations: []ecstypes.ServiceVolumeConfiguration{},
110-
ServiceRegistries: []ecstypes.ServiceRegistry{},
109+
VolumeConfigurations: envars.ServiceDefinitionInput.VolumeConfigurations,
110+
ServiceRegistries: envars.ServiceDefinitionInput.ServiceRegistries,
111111
DeploymentConfiguration: envars.ServiceDefinitionInput.DeploymentConfiguration,
112112
HealthCheckGracePeriodSeconds: envars.ServiceDefinitionInput.HealthCheckGracePeriodSeconds,
113113
EnableECSManagedTags: &envars.ServiceDefinitionInput.EnableECSManagedTags,
114-
PlacementConstraints: []ecstypes.PlacementConstraint{},
115-
PlacementStrategy: []ecstypes.PlacementStrategy{},
114+
PlacementConstraints: envars.ServiceDefinitionInput.PlacementConstraints,
115+
PlacementStrategy: envars.ServiceDefinitionInput.PlacementStrategy,
116116
PropagateTags: envars.ServiceDefinitionInput.PropagateTags,
117-
VpcLatticeConfigurations: []ecstypes.VpcLatticeConfiguration{},
117+
VpcLatticeConfigurations: envars.ServiceDefinitionInput.VpcLatticeConfigurations,
118118
}).
119119
DoAndReturn(mocker.Ecs.UpdateService),
120120
ecsMock.EXPECT().DescribeServices(gomock.Any(), gomock.Any(), gomock.Any()).

rollout/service_sync.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,19 @@ import (
55
)
66

77
func applyServiceDefinitionToUpdateInput(updateInput *ecs.UpdateServiceInput, serviceInput *ecs.CreateServiceInput) {
8-
// UpdateService treats omitted slice fields as "keep current", so explicitly
9-
// send empty slices for settings removed from service.json.
10-
updateInput.CapacityProviderStrategy = emptySliceIfNil(serviceInput.CapacityProviderStrategy)
11-
updateInput.LoadBalancers = emptySliceIfNil(serviceInput.LoadBalancers)
8+
// Preserve nil and empty slice distinctions from the service definition.
9+
updateInput.CapacityProviderStrategy = serviceInput.CapacityProviderStrategy
10+
updateInput.LoadBalancers = serviceInput.LoadBalancers
1211
updateInput.NetworkConfiguration = serviceInput.NetworkConfiguration
1312
updateInput.ServiceConnectConfiguration = serviceInput.ServiceConnectConfiguration
14-
updateInput.ServiceRegistries = emptySliceIfNil(serviceInput.ServiceRegistries)
13+
updateInput.ServiceRegistries = serviceInput.ServiceRegistries
1514
updateInput.PlatformVersion = serviceInput.PlatformVersion
16-
updateInput.VolumeConfigurations = emptySliceIfNil(serviceInput.VolumeConfigurations)
15+
updateInput.VolumeConfigurations = serviceInput.VolumeConfigurations
1716
updateInput.DeploymentConfiguration = serviceInput.DeploymentConfiguration
1817
updateInput.HealthCheckGracePeriodSeconds = serviceInput.HealthCheckGracePeriodSeconds
1918
updateInput.EnableECSManagedTags = &serviceInput.EnableECSManagedTags
20-
updateInput.PlacementConstraints = emptySliceIfNil(serviceInput.PlacementConstraints)
21-
updateInput.PlacementStrategy = emptySliceIfNil(serviceInput.PlacementStrategy)
19+
updateInput.PlacementConstraints = serviceInput.PlacementConstraints
20+
updateInput.PlacementStrategy = serviceInput.PlacementStrategy
2221
updateInput.PropagateTags = serviceInput.PropagateTags
23-
updateInput.VpcLatticeConfigurations = emptySliceIfNil(serviceInput.VpcLatticeConfigurations)
24-
}
25-
26-
func emptySliceIfNil[T any](s []T) []T {
27-
if s != nil {
28-
return s
29-
}
30-
return []T{}
22+
updateInput.VpcLatticeConfigurations = serviceInput.VpcLatticeConfigurations
3123
}

rollout/service_sync_test.go

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,45 @@ import (
99
)
1010

1111
func TestApplyServiceDefinitionToUpdateInput(t *testing.T) {
12-
updateInput := &ecs.UpdateServiceInput{}
13-
applyServiceDefinitionToUpdateInput(updateInput, &ecs.CreateServiceInput{})
12+
t.Run("preserves nil slice fields", func(t *testing.T) {
13+
updateInput := &ecs.UpdateServiceInput{}
14+
applyServiceDefinitionToUpdateInput(updateInput, &ecs.CreateServiceInput{})
1415

15-
assert.Equal(t, []ecstypes.CapacityProviderStrategyItem{}, updateInput.CapacityProviderStrategy)
16-
assert.Equal(t, []ecstypes.LoadBalancer{}, updateInput.LoadBalancers)
17-
assert.Equal(t, []ecstypes.ServiceRegistry{}, updateInput.ServiceRegistries)
18-
assert.Equal(t, []ecstypes.ServiceVolumeConfiguration{}, updateInput.VolumeConfigurations)
19-
assert.Equal(t, []ecstypes.PlacementConstraint{}, updateInput.PlacementConstraints)
20-
assert.Equal(t, []ecstypes.PlacementStrategy{}, updateInput.PlacementStrategy)
21-
assert.Equal(t, []ecstypes.VpcLatticeConfiguration{}, updateInput.VpcLatticeConfigurations)
16+
assert.Nil(t, updateInput.CapacityProviderStrategy)
17+
assert.Nil(t, updateInput.LoadBalancers)
18+
assert.Nil(t, updateInput.ServiceRegistries)
19+
assert.Nil(t, updateInput.VolumeConfigurations)
20+
assert.Nil(t, updateInput.PlacementConstraints)
21+
assert.Nil(t, updateInput.PlacementStrategy)
22+
assert.Nil(t, updateInput.VpcLatticeConfigurations)
2223

23-
assert.Nil(t, updateInput.NetworkConfiguration)
24-
assert.Nil(t, updateInput.ServiceConnectConfiguration)
25-
assert.Nil(t, updateInput.PlatformVersion)
26-
assert.Nil(t, updateInput.DeploymentConfiguration)
27-
assert.Nil(t, updateInput.HealthCheckGracePeriodSeconds)
28-
assert.Equal(t, ecstypes.PropagateTags(""), updateInput.PropagateTags)
24+
assert.Nil(t, updateInput.NetworkConfiguration)
25+
assert.Nil(t, updateInput.ServiceConnectConfiguration)
26+
assert.Nil(t, updateInput.PlatformVersion)
27+
assert.Nil(t, updateInput.DeploymentConfiguration)
28+
assert.Nil(t, updateInput.HealthCheckGracePeriodSeconds)
29+
assert.Equal(t, ecstypes.PropagateTags(""), updateInput.PropagateTags)
30+
})
31+
32+
t.Run("preserves explicit empty slice fields", func(t *testing.T) {
33+
serviceInput := &ecs.CreateServiceInput{
34+
CapacityProviderStrategy: []ecstypes.CapacityProviderStrategyItem{},
35+
LoadBalancers: []ecstypes.LoadBalancer{},
36+
ServiceRegistries: []ecstypes.ServiceRegistry{},
37+
VolumeConfigurations: []ecstypes.ServiceVolumeConfiguration{},
38+
PlacementConstraints: []ecstypes.PlacementConstraint{},
39+
PlacementStrategy: []ecstypes.PlacementStrategy{},
40+
VpcLatticeConfigurations: []ecstypes.VpcLatticeConfiguration{},
41+
}
42+
updateInput := &ecs.UpdateServiceInput{}
43+
applyServiceDefinitionToUpdateInput(updateInput, serviceInput)
44+
45+
assert.Equal(t, serviceInput.CapacityProviderStrategy, updateInput.CapacityProviderStrategy)
46+
assert.Equal(t, serviceInput.LoadBalancers, updateInput.LoadBalancers)
47+
assert.Equal(t, serviceInput.ServiceRegistries, updateInput.ServiceRegistries)
48+
assert.Equal(t, serviceInput.VolumeConfigurations, updateInput.VolumeConfigurations)
49+
assert.Equal(t, serviceInput.PlacementConstraints, updateInput.PlacementConstraints)
50+
assert.Equal(t, serviceInput.PlacementStrategy, updateInput.PlacementStrategy)
51+
assert.Equal(t, serviceInput.VpcLatticeConfigurations, updateInput.VpcLatticeConfigurations)
52+
})
2953
}

rollout_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func integrationTest(t *testing.T, env *env.Envars, lbcount int, input *types.Ro
108108
}
109109
}
110110

111-
func TestCage_RollOut_UpdateServiceRemovesOptionalSliceSettings(t *testing.T) {
111+
func TestCage_RollOut_UpdateServicePreservesNilOptionalSliceSettings(t *testing.T) {
112112
ctx := context.TODO()
113113
envars := test.DefaultEnvars()
114114
mocker := test.NewMockContext()
@@ -163,16 +163,11 @@ func TestCage_RollOut_UpdateServiceRemovesOptionalSliceSettings(t *testing.T) {
163163

164164
updatedService, _ := mocker.GetEcsService(envars.Service)
165165
assert.True(t, result.ServiceUpdated)
166-
assert.NotNil(t, updatedService.CapacityProviderStrategy)
167-
assert.Len(t, updatedService.CapacityProviderStrategy, 0)
168-
assert.NotNil(t, updatedService.LoadBalancers)
169-
assert.Len(t, updatedService.LoadBalancers, 0)
170-
assert.NotNil(t, updatedService.ServiceRegistries)
171-
assert.Len(t, updatedService.ServiceRegistries, 0)
172-
assert.NotNil(t, updatedService.PlacementConstraints)
173-
assert.Len(t, updatedService.PlacementConstraints, 0)
174-
assert.NotNil(t, updatedService.PlacementStrategy)
175-
assert.Len(t, updatedService.PlacementStrategy, 0)
166+
assert.Nil(t, updatedService.CapacityProviderStrategy)
167+
assert.Nil(t, updatedService.LoadBalancers)
168+
assert.Nil(t, updatedService.ServiceRegistries)
169+
assert.Nil(t, updatedService.PlacementConstraints)
170+
assert.Nil(t, updatedService.PlacementStrategy)
176171
}
177172

178173
func TestCage_Rollout_Failure(t *testing.T) {

0 commit comments

Comments
 (0)