From 018d2c6b1d23acf7fe67e809498bc354eaf6becf Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Mon, 14 May 2018 19:30:11 -0400 Subject: Add pod state Add a mutable state to pods, and database backend sutable for modifying and updating said state. Signed-off-by: Matthew Heon Closes: #784 Approved by: rhatdan --- libpod/in_memory_state.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'libpod/in_memory_state.go') diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go index 386ace5b6..36077b9d1 100644 --- a/libpod/in_memory_state.go +++ b/libpod/in_memory_state.go @@ -604,6 +604,36 @@ func (s *InMemoryState) RemoveContainerFromPod(pod *Pod, ctr *Container) error { return nil } +// UpdatePod updates a pod in the state +// This is a no-op as there is no backing store +func (s *InMemoryState) UpdatePod(pod *Pod) error { + if !pod.valid { + return ErrPodRemoved + } + + if _, ok := s.pods[pod.ID()]; !ok { + pod.valid = false + return errors.Wrapf(ErrNoSuchPod, "no pod exists in state with ID %s", pod.ID()) + } + + return nil +} + +// SavePod updates a pod in the state +// This is a no-op at there is no backing store +func (s *InMemoryState) SavePod(pod *Pod) error { + if !pod.valid { + return ErrPodRemoved + } + + if _, ok := s.pods[pod.ID()]; !ok { + pod.valid = false + return errors.Wrapf(ErrNoSuchPod, "no pod exists in state with ID %s", pod.ID()) + } + + return nil +} + // AllPods retrieves all pods currently in the state func (s *InMemoryState) AllPods() ([]*Pod, error) { pods := make([]*Pod, 0, len(s.pods)) -- cgit v1.2.3-54-g00ecf