summaryrefslogtreecommitdiff
path: root/libpod/in_memory_state.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-01-28 05:31:01 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-02-09 15:01:34 +0000
commit6b7b4b03a888b2d87dd58d1e8048d2a5c7e6a36b (patch)
tree69c319d68682370aabbb5185f996340042bd00d0 /libpod/in_memory_state.go
parentcfd6da22df9c580b8e6b6056a3ad0fbc1da71335 (diff)
downloadpodman-6b7b4b03a888b2d87dd58d1e8048d2a5c7e6a36b.tar.gz
podman-6b7b4b03a888b2d87dd58d1e8048d2a5c7e6a36b.tar.bz2
podman-6b7b4b03a888b2d87dd58d1e8048d2a5c7e6a36b.zip
Add pod removal code
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #268 Approved by: rhatdan
Diffstat (limited to 'libpod/in_memory_state.go')
-rw-r--r--libpod/in_memory_state.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go
index 2f0d2ec70..00e8ad4c3 100644
--- a/libpod/in_memory_state.go
+++ b/libpod/in_memory_state.go
@@ -423,6 +423,52 @@ func (s *InMemoryState) RemovePod(pod *Pod) error {
return nil
}
+// RemovePodContainers removes all containers from a pod
+// This is used to simultaneously remove a number of containers with
+// many interdependencies
+// Will only remove containers if no dependencies outside of the pod are present
+func (s *InMemoryState) RemovePodContainers(pod *Pod) error {
+ if !pod.valid {
+ return errors.Wrapf(ErrPodRemoved, "pod %s is not valid", pod.ID())
+ }
+
+ // Get pod containers
+ podCtrs, ok := s.podContainers[pod.ID()]
+ if !ok {
+ return errors.Wrapf(ErrNoSuchPod, "no pod exists in state with ID %s", pod.ID())
+ }
+
+ // Go through container dependencies. Check to see if any are outside the pod.
+ for ctr := range podCtrs {
+ ctrDeps, ok := s.ctrDepends[ctr]
+ if !ok {
+ return errors.Wrapf(ErrInternal, "cannot find dependencies for container %s", ctr)
+ }
+
+ for _, dep := range ctrDeps {
+ _, ok := podCtrs[dep]
+ if !ok {
+ return errors.Wrapf(ErrCtrExists, "container %s has dependency %s outside of pod %s", ctr, dep, pod.ID())
+ }
+ }
+ }
+
+ // All dependencies are OK to remove
+ // Remove all containers
+ s.podContainers[pod.ID()] = make(map[string]*Container)
+ for _, ctr := range podCtrs {
+ if err := s.ctrIDIndex.Delete(ctr.ID()); err != nil {
+ return errors.Wrapf(err, "error removing container ID from index")
+ }
+ s.ctrNameIndex.Release(ctr.Name())
+
+ delete(s.containers, ctr.ID())
+ delete(s.ctrDepends, ctr.ID())
+ }
+
+ return nil
+}
+
// AddContainerToPod adds a container to the given pod, also adding it to the
// state
func (s *InMemoryState) AddContainerToPod(pod *Pod, ctr *Container) error {