From b6db1380ecdc1bba6537779ddaac9c2e14257c13 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 8 Jan 2025 10:19:46 +0100 Subject: [PATCH] exclude one-off container running convergence Signed-off-by: Nicolas De Loof --- pkg/compose/containers.go | 13 +++++++++++-- pkg/compose/convergence.go | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/compose/containers.go b/pkg/compose/containers.go index 9b5e6bac4..4828cb919 100644 --- a/pkg/compose/containers.go +++ b/pkg/compose/containers.go @@ -114,6 +114,15 @@ func (s *composeService) getSpecifiedContainer(ctx context.Context, projectName // containerPredicate define a predicate we want container to satisfy for filtering operations type containerPredicate func(c moby.Container) bool +func matches(c moby.Container, predicates ...containerPredicate) bool { + for _, predicate := range predicates { + if !predicate(c) { + return false + } + } + return true +} + func isService(services ...string) containerPredicate { return func(c moby.Container) bool { service := c.Labels[api.ServiceLabel] @@ -148,10 +157,10 @@ func isNotOneOff(c moby.Container) bool { } // filter return Containers with elements to match predicate -func (containers Containers) filter(predicate containerPredicate) Containers { +func (containers Containers) filter(predicates ...containerPredicate) Containers { var filtered Containers for _, c := range containers { - if predicate(c) { + if matches(c, predicates...) { filtered = append(filtered, c) } } diff --git a/pkg/compose/convergence.go b/pkg/compose/convergence.go index acfdc6cdc..23992d8a1 100644 --- a/pkg/compose/convergence.go +++ b/pkg/compose/convergence.go @@ -460,7 +460,7 @@ func (s *composeService) waitDependencies(ctx context.Context, project *types.Pr continue } - waitingFor := containers.filter(isService(dep)) + waitingFor := containers.filter(isService(dep), isNotOneOff) w.Events(containerEvents(waitingFor, progress.Waiting)) if len(waitingFor) == 0 { if config.Required {