From c74a77e895db9bb79077541dd6040e0313dcf9d1 Mon Sep 17 00:00:00 2001 From: i-ky Date: Fri, 2 Dec 2022 10:19:21 +0000 Subject: [PATCH] Make use of Containers.filter() and isService() Signed-off-by: i-ky --- pkg/compose/convergence.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/pkg/compose/convergence.go b/pkg/compose/convergence.go index 1c92eaea1..710931f97 100644 --- a/pkg/compose/convergence.go +++ b/pkg/compose/convergence.go @@ -126,22 +126,13 @@ func updateServices(service *types.ServiceConfig, cnts Containers) { if len(cnts) == 0 { return } - serviceName2containerID := make(map[string]string) - for _, cnt := range cnts { - serviceName := cnt.Labels[api.ServiceLabel] - if _, exists := serviceName2containerID[serviceName]; !exists { - serviceName2containerID[serviceName] = cnt.ID - } - } - if id, found := serviceName2containerID[getDependentServiceFromMode(service.NetworkMode)]; found { - service.NetworkMode = types.NetworkModeContainerPrefix + id - } - if id, found := serviceName2containerID[getDependentServiceFromMode(service.Ipc)]; found { - service.Ipc = types.NetworkModeContainerPrefix + id - } - if id, found := serviceName2containerID[getDependentServiceFromMode(service.Pid)]; found { - service.Pid = types.NetworkModeContainerPrefix + id + for _, str := range []*string{&service.NetworkMode, &service.Ipc, &service.Pid} { + if d := getDependentServiceFromMode(*str); d != "" { + if serviceContainers := cnts.filter(isService(d)); len(serviceContainers) > 0 { + *str = types.NetworkModeContainerPrefix + serviceContainers[0].ID + } + } } var links []string for _, serviceLink := range service.Links {