Fix replacing "service:x" with "container:y"

Signed-off-by: i-ky <gl.ivanovsky@gmail.com>
This commit is contained in:
i-ky 2022-12-01 17:48:13 +02:00 committed by Nicolas De loof
parent 7cf5940f4a
commit 7f975fa40b
1 changed files with 13 additions and 8 deletions

View File

@ -126,17 +126,22 @@ func updateServices(service *types.ServiceConfig, cnts Containers) {
if len(cnts) == 0 {
return
}
cnt := cnts[0]
serviceName := cnt.Labels[api.ServiceLabel]
serviceName2containerID := make(map[string]string)
for _, cnt := range cnts {
serviceName := cnt.Labels[api.ServiceLabel]
if _, exists := serviceName2containerID[serviceName]; !exists {
serviceName2containerID[serviceName] = cnt.ID
}
}
if d := getDependentServiceFromMode(service.NetworkMode); d == serviceName {
service.NetworkMode = types.NetworkModeContainerPrefix + cnt.ID
if id, found := serviceName2containerID[getDependentServiceFromMode(service.NetworkMode)]; found {
service.NetworkMode = types.NetworkModeContainerPrefix + id
}
if d := getDependentServiceFromMode(service.Ipc); d == serviceName {
service.Ipc = types.NetworkModeContainerPrefix + cnt.ID
if id, found := serviceName2containerID[getDependentServiceFromMode(service.Ipc)]; found {
service.Ipc = types.NetworkModeContainerPrefix + id
}
if d := getDependentServiceFromMode(service.Pid); d == serviceName {
service.Pid = types.NetworkModeContainerPrefix + cnt.ID
if id, found := serviceName2containerID[getDependentServiceFromMode(service.Pid)]; found {
service.Pid = types.NetworkModeContainerPrefix + id
}
var links []string
for _, serviceLink := range service.Links {