Make use of Containers.filter() and isService()

Signed-off-by: i-ky <gl.ivanovsky@gmail.com>
This commit is contained in:
i-ky 2022-12-02 10:19:21 +00:00 committed by Nicolas De loof
parent 7f975fa40b
commit c74a77e895
1 changed files with 6 additions and 15 deletions

View File

@ -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 {