server: restore containers state from disk on startup
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
da0b8a6157
commit
a41ca975c1
2 changed files with 34 additions and 9 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
"github.com/containers/image/types"
|
||||
sstorage "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/oci"
|
||||
|
@ -19,7 +20,6 @@ import (
|
|||
"github.com/kubernetes-incubator/cri-o/pkg/storage"
|
||||
"github.com/kubernetes-incubator/cri-o/server/apparmor"
|
||||
"github.com/kubernetes-incubator/cri-o/server/seccomp"
|
||||
"github.com/moby/moby/pkg/ioutils"
|
||||
rspec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/opencontainers/selinux/go-selinux/label"
|
||||
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
|
||||
|
@ -122,7 +122,7 @@ func (s *Server) loadContainer(id string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
containerDir, err := s.store.GetContainerDirectory(id)
|
||||
containerDir, err := s.store.ContainerDirectory(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -149,13 +149,24 @@ func (s *Server) loadContainer(id string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = s.runtime.UpdateStatus(ctr); err != nil {
|
||||
return fmt.Errorf("error updating status for container %s: %v", ctr.ID(), err)
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -270,7 +281,7 @@ func (s *Server) loadSandbox(id string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
sandboxDir, err := s.store.GetContainerDirectory(id)
|
||||
sandboxDir, err := s.store.ContainerDirectory(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -294,9 +305,9 @@ func (s *Server) loadSandbox(id string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = s.runtime.UpdateStatus(scontainer); err != nil {
|
||||
return fmt.Errorf("error updating status for pod sandbox infra container %s: %v", scontainer.ID(), err)
|
||||
}
|
||||
|
||||
s.containerStateFromDisk(scontainer)
|
||||
|
||||
if err = label.ReserveLabel(processLabel); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue