move containerState to/from disk to libkpod

Signed-off-by: Ryan Cole <rcyoalne@gmail.com>
This commit is contained in:
Ryan Cole 2017-07-20 13:05:12 -04:00
parent 1aa0d5da86
commit d625e0e468
9 changed files with 40 additions and 35 deletions

View file

@ -13,7 +13,6 @@ import (
"github.com/Sirupsen/logrus"
"github.com/containers/image/types"
cstorage "github.com/containers/storage"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/registrar"
"github.com/docker/docker/pkg/truncindex"
"github.com/kubernetes-incubator/cri-o/libkpod"
@ -158,37 +157,12 @@ func (s *Server) loadContainer(id string) error {
return err
}
s.containerStateFromDisk(ctr)
s.ContainerStateFromDisk(ctr)
s.addContainer(ctr)
return s.CtrIDIndex().Add(id)
}
func (s *Server) containerStateFromDisk(c *oci.Container) error {
if err := c.FromDisk(); err != nil {
return err
}
// ignore errors, this is a best effort to have up-to-date info about
// a given container before its state gets stored
s.Runtime().UpdateStatus(c)
return nil
}
func (s *Server) containerStateToDisk(c *oci.Container) error {
// ignore errors, this is a best effort to have up-to-date info about
// a given container before its state gets stored
s.Runtime().UpdateStatus(c)
jsonSource, err := ioutils.NewAtomicFileWriter(c.StatePath(), 0644)
if err != nil {
return err
}
defer jsonSource.Close()
enc := json.NewEncoder(jsonSource)
return enc.Encode(s.Runtime().ContainerStatus(c))
}
func configNetNsPath(spec rspec.Spec) (string, error) {
for _, ns := range spec.Linux.Namespaces {
if ns.Type != rspec.NetworkNamespace {
@ -302,7 +276,7 @@ func (s *Server) loadSandbox(id string) error {
return err
}
s.containerStateFromDisk(scontainer)
s.ContainerStateFromDisk(scontainer)
if err = label.ReserveLabel(processLabel); err != nil {
return err