summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libpod/in_memory_state.go19
-rw-r--r--libpod/runtime.go7
-rw-r--r--libpod/runtime_ctr.go10
3 files changed, 19 insertions, 17 deletions
diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go
index 19d14366c..9a2b74c2a 100644
--- a/libpod/in_memory_state.go
+++ b/libpod/in_memory_state.go
@@ -188,8 +188,7 @@ func (s *InMemoryState) UpdateContainer(ctr *Container) error {
}
// If the container does not exist, return error
- _, ok := s.containers[ctr.ID()]
- if !ok {
+ if _, ok := s.containers[ctr.ID()]; !ok {
ctr.valid = false
return errors.Wrapf(ErrNoSuchCtr, "container with ID %s not found in state", ctr.ID())
}
@@ -208,8 +207,7 @@ func (s *InMemoryState) SaveContainer(ctr *Container) error {
}
// If the container does not exist, return error
- _, ok := s.containers[ctr.ID()]
- if !ok {
+ if _, ok := s.containers[ctr.ID()]; !ok {
ctr.valid = false
return errors.Wrapf(ErrNoSuchCtr, "container with ID %s not found in state", ctr.ID())
}
@@ -371,7 +369,8 @@ func (s *InMemoryState) UpdatePod(pod *Pod) error {
func (s *InMemoryState) AddContainerToPod(pod *Pod, ctr *Container) error {
if !pod.valid {
return errors.Wrapf(ErrPodRemoved, "pod %s is not valid and cannot be added to", pod.ID())
- } else if !ctr.valid {
+ }
+ if !ctr.valid {
return errors.Wrapf(ErrCtrRemoved, "container %s is not valid and cannot be added to the pod", ctr.ID())
}
@@ -391,12 +390,12 @@ func (s *InMemoryState) AddContainerToPod(pod *Pod, ctr *Container) error {
}
if err := s.ctrNameIndex.Reserve(ctr.Name(), ctr.ID()); err != nil {
- return errors.Wrapf(err, "error registering container name %s", ctr.Name())
+ return errors.Wrapf(err, "error reserving container name %s", ctr.Name())
}
if err := s.ctrIDIndex.Add(ctr.ID()); err != nil {
s.ctrNameIndex.Release(ctr.Name())
- return errors.Wrapf(err, "error registering container ID %s", ctr.ID())
+ return errors.Wrapf(err, "error releasing container ID %s", ctr.ID())
}
s.containers[ctr.ID()] = ctr
@@ -409,7 +408,8 @@ func (s *InMemoryState) AddContainerToPod(pod *Pod, ctr *Container) error {
func (s *InMemoryState) RemoveContainerFromPod(pod *Pod, ctr *Container) error {
if !pod.valid {
return errors.Wrapf(ErrPodRemoved, "pod %s is not valid and containers cannot be removed", pod.ID())
- } else if !ctr.valid {
+ }
+ if !ctr.valid {
return errors.Wrapf(ErrCtrRemoved, "container %s is not valid and cannot be removed from the pod", ctr.ID())
}
@@ -417,7 +417,8 @@ func (s *InMemoryState) RemoveContainerFromPod(pod *Pod, ctr *Container) error {
exists, err := pod.HasContainer(ctr.ID())
if err != nil {
return errors.Wrapf(err, "error checking for container %s in pod %s", ctr.ID(), pod.ID())
- } else if !exists {
+ }
+ if !exists {
return errors.Wrapf(ErrNoSuchCtr, "no container %s in pod %s", ctr.ID(), pod.ID())
}
diff --git a/libpod/runtime.go b/libpod/runtime.go
index dc258ab4f..d0362ec79 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -191,13 +191,14 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
runtime.netPlugin = netPlugin
// Set up the state
- if runtime.config.StateType == InMemoryStateStore {
+ switch runtime.config.StateType {
+ case InMemoryStateStore:
state, err := NewInMemoryState()
if err != nil {
return nil, err
}
runtime.state = state
- } else if runtime.config.StateType == SQLiteStateStore {
+ case SQLiteStateStore:
dbPath := filepath.Join(runtime.config.StaticDir, "sql_state.db")
specsDir := filepath.Join(runtime.config.StaticDir, "ocispec")
@@ -215,7 +216,7 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
return nil, err
}
runtime.state = state
- } else {
+ default:
return nil, errors.Wrapf(ErrInvalidArg, "unrecognized state type passed")
}
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index bc1b6bc2f..42f3dd892 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -82,11 +82,11 @@ func (r *Runtime) NewContainer(rSpec *spec.Spec, options ...CtrCreateOption) (c
}
if err := r.state.AddContainerToPod(pod, ctr); err != nil {
- return nil, errors.Wrapf(err, "error adding new container to state")
+ return nil, err
}
} else {
if err := r.state.AddContainer(ctr); err != nil {
- return nil, errors.Wrapf(err, "error adding new container to state")
+ return nil, err
}
}
@@ -166,17 +166,17 @@ func (r *Runtime) removeContainer(c *Container, force bool) error {
}
if err := r.state.RemoveContainerFromPod(pod, c); err != nil {
- return errors.Wrapf(err, "error removing container %s from state", c.ID())
+ return err
}
} else {
if err := r.state.RemoveContainer(c); err != nil {
- return errors.Wrapf(err, "error removing container from state")
+ return err
}
}
// Delete the container
// Only do this if we're not ContainerStateConfigured - if we are,
- // we haven't been created in runc yet
+ // we haven't been created in the runtime yet
if c.state.State == ContainerStateConfigured {
if err := r.ociRuntime.deleteContainer(c); err != nil {
return errors.Wrapf(err, "error removing container %s from runc", c.ID())