diff --git a/pkg/domain/dockerCompose/config.go b/pkg/domain/dockerCompose/config.go index 7d4783a..ae463f6 100644 --- a/pkg/domain/dockerCompose/config.go +++ b/pkg/domain/dockerCompose/config.go @@ -508,7 +508,14 @@ func (sd *ServiceDeploy) MergeLastWin(serviceDeploy *ServiceDeploy) { } func (sd *ServiceDeploy) mergeLastWinDeployResources(resources *ServiceDeployResources) { - if !sd.Resources.Equal(resources) { + switch { + case sd.Resources == nil && resources != nil: + sd.Resources = resources + case sd.Resources != nil && resources == nil: + fallthrough + case sd.Resources == nil && resources == nil: + return + default: sd.Resources.MergeLastWin(resources) } } diff --git a/pkg/domain/dockerCompose/config_test.go b/pkg/domain/dockerCompose/config_test.go index 1c7cc2d..8179111 100644 --- a/pkg/domain/dockerCompose/config_test.go +++ b/pkg/domain/dockerCompose/config_test.go @@ -505,6 +505,68 @@ func TestSecretDeploy_Equal(t *testing.T) { } } +func TestServiceDeploy_MergeLastWin(t *testing.T) { + require := require.New(t) + + testCases := []struct { + serviceDeploymentA *dockerCompose.ServiceDeploy + serviceDeploymentB *dockerCompose.ServiceDeploy + expectedServiceDeployment *dockerCompose.ServiceDeploy + }{ + { + serviceDeploymentA: nil, + serviceDeploymentB: nil, + expectedServiceDeployment: nil, + }, + { + serviceDeploymentA: &dockerCompose.ServiceDeploy{ + Resources: nil, + }, + serviceDeploymentB: &dockerCompose.ServiceDeploy{ + Resources: nil, + }, + expectedServiceDeployment: &dockerCompose.ServiceDeploy{ + Resources: nil, + }, + }, + { + serviceDeploymentA: &dockerCompose.ServiceDeploy{ + Resources: &dockerCompose.ServiceDeployResources{ + Limits: nil, + }, + }, + serviceDeploymentB: &dockerCompose.ServiceDeploy{ + Resources: nil, + }, + expectedServiceDeployment: &dockerCompose.ServiceDeploy{ + Resources: &dockerCompose.ServiceDeployResources{ + Limits: nil, + }, + }, + }, + { + serviceDeploymentA: &dockerCompose.ServiceDeploy{ + Resources: nil, + }, + serviceDeploymentB: &dockerCompose.ServiceDeploy{ + Resources: &dockerCompose.ServiceDeployResources{ + Limits: nil, + }, + }, + expectedServiceDeployment: &dockerCompose.ServiceDeploy{ + Resources: &dockerCompose.ServiceDeployResources{ + Limits: nil, + }, + }, + }, + } + + for i, testCase := range testCases { + testCase.serviceDeploymentA.MergeLastWin(testCase.serviceDeploymentB) + require.True(testCase.expectedServiceDeployment.Equal(testCase.serviceDeploymentA), "Failed test case %v", i) + } +} + func TestSecretDeployResources_Equal(t *testing.T) { require := require.New(t)