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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
s.releaseContainerName(name)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
var metadata pb.ContainerMetadata
|
var metadata pb.ContainerMetadata
|
||||||
if err = json.Unmarshal([]byte(m.Annotations["ocid/metadata"]), &metadata); err != nil {
|
if err = json.Unmarshal([]byte(m.Annotations["ocid/metadata"]), &metadata); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sb := s.getSandbox(m.Annotations["ocid/sandbox_id"])
|
sb := s.getSandbox(m.Annotations["ocid/sandbox_id"])
|
||||||
if sb == nil {
|
if sb == nil {
|
||||||
logrus.Warnf("could not get sandbox with id %s, skipping", m.Annotations["ocid/sandbox_id"])
|
return fmt.Errorf("could not get sandbox with id %s, skipping", m.Annotations["ocid/sandbox_id"])
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var tty bool
|
var tty bool
|
||||||
|
@ -104,11 +110,10 @@ func (s *Server) loadContainer(id string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
s.addContainer(ctr)
|
|
||||||
if err = s.runtime.UpdateStatus(ctr); err != nil {
|
if err = s.runtime.UpdateStatus(ctr); err != nil {
|
||||||
logrus.Warnf("error updating status for container %s: %v", ctr.ID(), err)
|
return fmt.Errorf("error updating status for container %s: %v", ctr.ID(), err)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
s.addContainer(ctr)
|
||||||
if err = s.ctrIDIndex.Add(id); err != nil {
|
if err = s.ctrIDIndex.Add(id); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -149,6 +154,11 @@ func (s *Server) loadSandbox(id string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
s.releasePodName(name)
|
||||||
|
}
|
||||||
|
}()
|
||||||
var metadata pb.PodSandboxMetadata
|
var metadata pb.PodSandboxMetadata
|
||||||
if err = json.Unmarshal([]byte(m.Annotations["ocid/metadata"]), &metadata); err != nil {
|
if err = json.Unmarshal([]byte(m.Annotations["ocid/metadata"]), &metadata); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -194,28 +204,37 @@ func (s *Server) loadSandbox(id string) error {
|
||||||
|
|
||||||
s.addSandbox(sb)
|
s.addSandbox(sb)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
s.removeSandbox(sb.id)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
sandboxPath, err := s.store.GetContainerRunDirectory(id)
|
sandboxPath, err := s.store.GetContainerRunDirectory(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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"])
|
cname, err := s.reserveContainerName(m.Annotations["ocid/container_id"], m.Annotations["ocid/container_name"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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)
|
scontainer, err := oci.NewContainer(m.Annotations["ocid/container_id"], cname, sandboxPath, sandboxPath, sb.netNs(), labels, annotations, nil, nil, id, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sb.infraContainer = scontainer
|
|
||||||
if err = s.runtime.UpdateStatus(scontainer); err != nil {
|
if err = s.runtime.UpdateStatus(scontainer); err != nil {
|
||||||
logrus.Warnf("error updating status for pod sandbox infra container %s: %v", scontainer.ID(), err)
|
return fmt.Errorf("error updating status for pod sandbox infra container %s: %v", scontainer.ID(), err)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
if err = label.ReserveLabel(processLabel); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sb.infraContainer = scontainer
|
||||||
if err = s.ctrIDIndex.Add(scontainer.ID()); err != nil {
|
if err = s.ctrIDIndex.Add(scontainer.ID()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue