diff options
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/container.go | 6 | ||||
-rw-r--r-- | libpod/in_memory_state.go | 27 |
2 files changed, 17 insertions, 16 deletions
diff --git a/libpod/container.go b/libpod/container.go index 4d6fe3a5e..2ee87163d 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -336,7 +336,11 @@ func (c *Container) Dependencies() []string { dependsCtrs[c.config.CgroupNsCtr] = true } - depends := make([]string, len(dependsCtrs), 0) + if len(dependsCtrs) == 0 { + return []string{} + } + + depends := make([]string, 0, len(dependsCtrs)) for ctr, _ := range dependsCtrs { depends = append(depends, ctr) } diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go index 9a2b74c2a..55162e6c8 100644 --- a/libpod/in_memory_state.go +++ b/libpod/in_memory_state.go @@ -26,6 +26,8 @@ func NewInMemoryState() (State, error) { state.pods = make(map[string]*Pod) state.containers = make(map[string]*Container) + state.ctrDepends = make(map[string][]string) + state.podNameIndex = registrar.NewRegistrar() state.ctrNameIndex = registrar.NewRegistrar() @@ -131,13 +133,10 @@ func (s *InMemoryState) AddContainer(ctr *Container) error { s.containers[ctr.ID()] = ctr // Add containers this container depends on - s.addCtrToDependsMap(ctr.ID(), ctr.config.IPCNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.MountNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.NetNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.PIDNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.UserNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.UTSNsCtr) - s.addCtrToDependsMap(ctr.ID(), ctr.config.CgroupNsCtr) + depCtrs := ctr.Dependencies() + for _, depCtr := range depCtrs { + s.addCtrToDependsMap(ctr.ID(), depCtr) + } return nil } @@ -167,13 +166,11 @@ func (s *InMemoryState) RemoveContainer(ctr *Container) error { delete(s.ctrDepends, ctr.ID()) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.IPCNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.MountNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.NetNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.PIDNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.UserNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.UTSNsCtr) - s.removeCtrFromDependsMap(ctr.ID(), ctr.config.CgroupNsCtr) + // Remove us from container dependencies + depCtrs := ctr.Dependencies() + for _, depCtr := range depCtrs { + s.removeCtrFromDependsMap(ctr.ID(), depCtr) + } return nil } @@ -479,7 +476,7 @@ func (s *InMemoryState) removeCtrFromDependsMap(ctrID, dependsID string) { return } - newArr := make([]string, len(arr), 0) + newArr := make([]string, 0, len(arr)) for _, id := range arr { if id != ctrID { |