server: cleanup on failed restore
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
437459bd64
commit
749d24fbab
1 changed files with 31 additions and 12 deletions
|
@ -68,14 +68,20 @@ func (s *Server) loadContainer(id string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
s.releaseContainerName(name)
|
||||
}
|
||||
}()
|
||||
|
||||
var metadata pb.ContainerMetadata
|
||||
if err = json.Unmarshal([]byte(m.Annotations["ocid/metadata"]), &metadata); err != nil {
|
||||
return err
|
||||
}
|
||||
sb := s.getSandbox(m.Annotations["ocid/sandbox_id"])
|
||||
if sb == nil {
|
||||
logrus.Warnf("could not get sandbox with id %s, skipping", m.Annotations["ocid/sandbox_id"])
|
||||
return nil
|
||||
return fmt.Errorf("could not get sandbox with id %s, skipping", m.Annotations["ocid/sandbox_id"])
|
||||
}
|
||||
|
||||
var tty bool
|
||||
|
@ -104,11 +110,10 @@ func (s *Server) loadContainer(id string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.addContainer(ctr)
|
||||
if err = s.runtime.UpdateStatus(ctr); err != nil {
|
||||
logrus.Warnf("error updating status for container %s: %v", ctr.ID(), err)
|
||||
return nil
|
||||
return fmt.Errorf("error updating status for container %s: %v", ctr.ID(), err)
|
||||
}
|
||||
s.addContainer(ctr)
|
||||
if err = s.ctrIDIndex.Add(id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -149,6 +154,11 @@ func (s *Server) loadSandbox(id string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
s.releasePodName(name)
|
||||
}
|
||||
}()
|
||||
var metadata pb.PodSandboxMetadata
|
||||
if err = json.Unmarshal([]byte(m.Annotations["ocid/metadata"]), &metadata); err != nil {
|
||||
return err
|
||||
|
@ -194,28 +204,37 @@ func (s *Server) loadSandbox(id string) error {
|
|||
|
||||
s.addSandbox(sb)
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
s.removeSandbox(sb.id)
|
||||
}
|
||||
}()
|
||||
|
||||
sandboxPath, err := s.store.GetContainerRunDirectory(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = label.ReserveLabel(processLabel); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cname, err := s.reserveContainerName(m.Annotations["ocid/container_id"], m.Annotations["ocid/container_name"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
s.releaseContainerName(cname)
|
||||
}
|
||||
}()
|
||||
scontainer, err := oci.NewContainer(m.Annotations["ocid/container_id"], cname, sandboxPath, sandboxPath, sb.netNs(), labels, annotations, nil, nil, id, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sb.infraContainer = scontainer
|
||||
if err = s.runtime.UpdateStatus(scontainer); err != nil {
|
||||
logrus.Warnf("error updating status for pod sandbox infra container %s: %v", scontainer.ID(), err)
|
||||
return nil
|
||||
return fmt.Errorf("error updating status for pod sandbox infra container %s: %v", scontainer.ID(), err)
|
||||
}
|
||||
if err = label.ReserveLabel(processLabel); err != nil {
|
||||
return err
|
||||
}
|
||||
sb.infraContainer = scontainer
|
||||
if err = s.ctrIDIndex.Add(scontainer.ID()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue