From 07b9d93f5f94673921dc833167710178a42c0d71 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 3 Feb 2022 08:05:35 +0000 Subject: [PATCH] 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 --- src/runtime/virtcontainers/sandbox.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index ec6a3d780..9c7ebaf1a 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -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 }