Skip to content
This repository was archived by the owner on Feb 1, 2021. It is now read-only.

Fix bug: In RefreshContainers, containers created after ListContainers are lost #2190

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cluster/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,13 @@ func (e *Engine) refreshVolume(IDOrName string) error {
// true, each container will be inspected.
// FIXME: unexport this method after mesos scheduler stops using it directly
func (e *Engine) RefreshContainers(full bool) error {
oldContainers := []string{}
e.RLock()
for id := range e.containers {
oldContainers = append(oldContainers, id)
}
e.RUnlock()

opts := types.ContainerListOptions{
All: true,
Size: false,
Expand All @@ -750,7 +757,14 @@ func (e *Engine) RefreshContainers(full bool) error {

e.Lock()
defer e.Unlock()
e.containers = merged
for id, c := range merged {
e.containers[id] = c
}
for _, id := range oldContainers {
if _, exists := merged[id]; !exists {
delete(e.containers, id)
}
}

return nil
}
Expand Down
3 changes: 2 additions & 1 deletion cluster/swarm/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func (p *pendingContainer) ToContainer() *cluster.Container {
Config: p.Config,
Info: types.ContainerJSON{
ContainerJSONBase: &types.ContainerJSONBase{
HostConfig: &containertypes.HostConfig{},
HostConfig: &p.Config.HostConfig,
},
Config: &p.Config.Config,
},
Engine: p.Engine,
}
Expand Down