virtcontainer: Simplify the sandbox network creation flow

We don't need to call NewNetwork() twice, and we can have the VM factory
case return immediatly. That makes the code more readable.

Signed-off-by: Samuel Ortiz <s.ortiz@apple.com>
This commit is contained in:
Samuel Ortiz 2022-02-03 08:05:35 +00:00 committed by Samuel Ortiz
parent 2c7087ff42
commit 07b9d93f5f

View File

@ -804,24 +804,19 @@ func (s *Sandbox) createNetwork(ctx context.Context) error {
span, ctx := katatrace.Trace(ctx, s.Logger(), "createNetwork", sandboxTracingTags, map[string]string{"sandbox_id": s.id})
defer span.End()
network, err := NewNetwork(&s.config.NetworkConfig)
if err != nil {
return err
}
s.network = network
katatrace.AddTags(span, "network", s.network, "NetworkConfig", s.config.NetworkConfig)
// In case there is a factory, network interfaces are hotplugged
// after vm is started.
if s.factory == nil {
// Add the network
if _, err := s.network.AddEndpoints(ctx, s, nil, false); err != nil {
return err
}
// after the vm is started.
if s.factory != nil {
return nil
}
// Add all the networking endpoints.
if _, err := s.network.AddEndpoints(ctx, s, nil, false); err != nil {
return err
}
return nil
}