mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
runtime: it should rollback when failed in Sandbox AddInterface
When Sandbox AddInterface() is called, it may fail after endpoint.HotAttach, we'd better rollback and call save() in the end. Fixes: #3419 Signed-off-by: yangfeiyu <yangfeiyu20102011@163.com>
This commit is contained in:
parent
97e18cf2d0
commit
b133a2368a
@ -869,15 +869,28 @@ func (s *Sandbox) AddInterface(ctx context.Context, inf *pbTypes.Interface) (*pb
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the sandbox storage
|
defer func() {
|
||||||
s.networkNS.Endpoints = append(s.networkNS.Endpoints, endpoint)
|
if err != nil {
|
||||||
if err := s.Save(); err != nil {
|
if errDetach := endpoint.HotDetach(ctx, s.hypervisor, s.networkNS.NetNsCreated, s.networkNS.NetNsPath); errDetach != nil {
|
||||||
return nil, err
|
s.Logger().WithField("endpoint-type", endpoint.Type()).WithError(errDetach).Error("rollback hot attaching endpoint failed")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Add network for vm
|
// Add network for vm
|
||||||
inf.PciPath = endpoint.PciPath().String()
|
inf.PciPath = endpoint.PciPath().String()
|
||||||
return s.agent.updateInterface(ctx, inf)
|
result, err := s.agent.updateInterface(ctx, inf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the sandbox storage
|
||||||
|
s.networkNS.Endpoints = append(s.networkNS.Endpoints, endpoint)
|
||||||
|
if err = s.Save(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveInterface removes a nic of the sandbox.
|
// RemoveInterface removes a nic of the sandbox.
|
||||||
|
Loading…
Reference in New Issue
Block a user