mirror of
https://github.com/containrrr/watchtower.git
synced 2026-02-26 00:44:08 +01:00
add additional test and further rework client mocks
This commit is contained in:
parent
abbdaa834c
commit
e97671f293
6 changed files with 384 additions and 67 deletions
|
|
@ -157,12 +157,18 @@ func (client dockerClient) GetContainer(containerID t.ContainerID) (t.Container,
|
|||
return &Container{}, err
|
||||
}
|
||||
|
||||
containerNetworkMode := strings.Split(string(containerInfo.HostConfig.NetworkMode), ":")
|
||||
if len(containerNetworkMode) == 2 && containerNetworkMode[0] == "container" {
|
||||
parentContainer, err := client.api.ContainerInspect(bg, containerNetworkMode[1])
|
||||
netType, netContainerId, found := strings.Cut(string(containerInfo.HostConfig.NetworkMode), ":")
|
||||
if found && netType == "container" {
|
||||
parentContainer, err := client.api.ContainerInspect(bg, netContainerId)
|
||||
if err != nil {
|
||||
log.Debug("Unable to fetch parentContainer.")
|
||||
log.WithFields(map[string]interface{}{
|
||||
"container": containerInfo.Name,
|
||||
"error": err,
|
||||
"network-container": netContainerId,
|
||||
}).Warnf("Unable to resolve network container: %v", err)
|
||||
|
||||
} else {
|
||||
// Replace the container ID with a container name to allow it to reference the re-created network container
|
||||
containerInfo.HostConfig.NetworkMode = container.NetworkMode(fmt.Sprintf("container:%s", parentContainer.Name))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue