From 0c386f74f9447d82bb03061dfc40ef8516f8d2a2 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Thu, 25 Aug 2016 12:14:59 -0700 Subject: [PATCH] Track container removal in state Signed-off-by: Mrunal Patel --- server/server.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server/server.go b/server/server.go index 4c3f0463..ee557de7 100644 --- a/server/server.go +++ b/server/server.go @@ -59,7 +59,7 @@ type sandbox struct { name string logDir string labels map[string]string - containers []*oci.Container + containers map[string]*oci.Container } func (s *Server) addSandbox(sb *sandbox) { @@ -72,7 +72,11 @@ func (s *Server) hasSandbox(name string) bool { } func (s *sandbox) addContainer(c *oci.Container) { - s.containers = append(s.containers, c) + s.containers[c.Name()] = c +} + +func (s *sandbox) removeContainer(c *oci.Container) { + delete(s.containers, c.Name()) } func (s *Server) addContainer(c *oci.Container) { @@ -80,3 +84,9 @@ func (s *Server) addContainer(c *oci.Container) { sandbox.addContainer(c) s.state.containers[c.Name()] = c } + +func (s *Server) removeContainer(c *oci.Container) { + sandbox := s.state.sandboxes[c.Sandbox()] + sandbox.removeContainer(c) + delete(s.state.containers, c.Name()) +}