Merge pull request #23644 from tonistiigi/fix-leave-delete

Fix removing containers on leaving from pending state
This commit is contained in:
Arnaud Porterie 2016-06-17 01:40:45 +00:00 коммит произвёл GitHub
Родитель edfd546a6f 826f6f0703
Коммит f4de3f314e
2 изменённых файлов: 31 добавлений и 4 удалений

Просмотреть файл

@ -389,10 +389,11 @@ func (c *Cluster) Leave(force bool) error {
if err := node.Stop(ctx); err != nil && !strings.Contains(err.Error(), "context canceled") {
return err
}
nodeID := node.NodeID()
for _, id := range c.config.Backend.ListContainersForNode(nodeID) {
if err := c.config.Backend.ContainerRm(id, &apitypes.ContainerRmConfig{ForceRemove: true}); err != nil {
logrus.Errorf("error removing %v: %v", id, err)
if nodeID := node.NodeID(); nodeID != "" {
for _, id := range c.config.Backend.ListContainersForNode(nodeID) {
if err := c.config.Backend.ContainerRm(id, &apitypes.ContainerRmConfig{ForceRemove: true}); err != nil {
logrus.Errorf("error removing %v: %v", id, err)
}
}
}
c.Lock()

Просмотреть файл

@ -552,6 +552,32 @@ func (s *DockerSwarmSuite) TestApiSwarmLeaveRemovesContainer(c *check.C) {
c.Assert(id, checker.HasPrefix, strings.TrimSpace(id2))
}
// #23629
func (s *DockerSwarmSuite) TestApiSwarmLeaveOnPendingJoin(c *check.C) {
s.AddDaemon(c, true, true)
d2 := s.AddDaemon(c, false, false)
id, err := d2.Cmd("run", "-d", "busybox", "top")
c.Assert(err, checker.IsNil)
id = strings.TrimSpace(id)
go d2.Join("nosuchhost:1234", "", "", false) // will block on pending state
time.Sleep(1 * time.Second)
info, err := d2.info()
c.Assert(err, checker.IsNil)
c.Assert(info.LocalNodeState, checker.Equals, swarm.LocalNodeStatePending)
c.Assert(d2.Leave(true), checker.IsNil)
waitAndAssert(c, defaultReconciliationTimeout, d2.checkActiveContainerCount, checker.Equals, 1)
id2, err := d2.Cmd("ps", "-q")
c.Assert(err, checker.IsNil)
c.Assert(id, checker.HasPrefix, strings.TrimSpace(id2))
}
func (s *DockerSwarmSuite) TestApiSwarmManagerRestore(c *check.C) {
d1 := s.AddDaemon(c, true, true)