From 09e0fa94b8088916bf60806a0ac7407ec7bc721c Mon Sep 17 00:00:00 2001 From: Guillaume Lours Date: Sat, 19 Feb 2022 21:17:51 +0100 Subject: [PATCH] do not wait for dependencies with scale 0 Signed-off-by: Guillaume Lours --- pkg/compose/convergence.go | 6 ++++++ pkg/compose/convergence_test.go | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pkg/compose/convergence.go b/pkg/compose/convergence.go index 24f051ee2..aa81fb37f 100644 --- a/pkg/compose/convergence.go +++ b/pkg/compose/convergence.go @@ -280,6 +280,12 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr // already managed by InDependencyOrder return nil } + if service, err := project.GetService(dep); err != nil { + return err + } else if service.Scale == 0 { + // don't wait for the dependency which configured to have 0 containers running + continue + } containers, err := s.getContainers(ctx, project.Name, oneOffExclude, false, dep) if err != nil { diff --git a/pkg/compose/convergence_test.go b/pkg/compose/convergence_test.go index 0b647c6b4..69bc39086 100644 --- a/pkg/compose/convergence_test.go +++ b/pkg/compose/convergence_test.go @@ -19,6 +19,7 @@ package compose import ( "context" "fmt" + "strings" "testing" "github.com/compose-spec/compose-go/types" @@ -184,3 +185,21 @@ func TestServiceLinks(t *testing.T) { assert.Equal(t, links[2], "testProject-web-1:testProject-web-1") }) } + +func TestWaitDependencies(t *testing.T) { + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + api := mocks.NewMockAPIClient(mockCtrl) + tested.apiClient = api + + t.Run("should skip dependencies with scale 0", func(t *testing.T) { + dbService := types.ServiceConfig{Name: "db", Scale: 0} + redisService := types.ServiceConfig{Name: "redis", Scale: 0} + project := types.Project{Name: strings.ToLower(testProject), Services: []types.ServiceConfig{dbService, redisService}} + dependencies := types.DependsOnConfig{ + "db": {Condition: ServiceConditionRunningOrHealthy}, + "redis": {Condition: ServiceConditionRunningOrHealthy}, + } + assert.NilError(t, tested.waitDependencies(context.Background(), &project, dependencies)) + }) +}