virtcontainers: Network API cleanups and simplifications

Remove unused parameters.
Reduce the number of parameters by deriving some of them (e.g. a
networking config) from their outer structure (e.g. a Sandbox
reference).

Signed-off-by: Samuel Ortiz <s.ortiz@apple.com>
This commit is contained in:
Samuel Ortiz 2021-11-06 06:56:50 +01:00 committed by Samuel Ortiz
parent 2edea88369
commit d7b67a7d1a
2 changed files with 9 additions and 9 deletions

View File

@ -439,7 +439,7 @@ func (n *Network) attachEndpoints(ctx context.Context, s *Sandbox, hotplug bool)
} }
// Run runs a callback in the specified network namespace. // Run runs a callback in the specified network namespace.
func (n *Network) Run(ctx context.Context, _ string, cb func() error) error { func (n *Network) Run(ctx context.Context, cb func() error) error {
span, _ := n.trace(ctx, "Run") span, _ := n.trace(ctx, "Run")
defer span.End() defer span.End()
@ -449,7 +449,7 @@ func (n *Network) Run(ctx context.Context, _ string, cb func() error) error {
} }
// Add adds all needed interfaces inside the network namespace. // Add adds all needed interfaces inside the network namespace.
func (n *Network) Add(ctx context.Context, config *NetworkConfig, s *Sandbox, hotplug bool) ([]Endpoint, error) { func (n *Network) Add(ctx context.Context, s *Sandbox, hotplug bool) ([]Endpoint, error) {
span, ctx := n.trace(ctx, "Add") span, ctx := n.trace(ctx, "Add")
katatrace.AddTags(span, "type", n.InterworkingModel.GetModel()) katatrace.AddTags(span, "type", n.InterworkingModel.GetModel())
defer span.End() defer span.End()
@ -464,7 +464,7 @@ func (n *Network) Add(ctx context.Context, config *NetworkConfig, s *Sandbox, ho
return n.Endpoints, nil return n.Endpoints, nil
} }
func (n *Network) PostAdd(ctx context.Context, _ *NetworkNamespace, hotplug bool) error { func (n *Network) PostAdd(ctx context.Context, hotplug bool) error {
if hotplug { if hotplug {
return nil return nil
} }
@ -492,7 +492,7 @@ func (n *Network) PostAdd(ctx context.Context, _ *NetworkNamespace, hotplug bool
// Remove network endpoints in the network namespace. It also deletes the network // Remove network endpoints in the network namespace. It also deletes the network
// namespace in case the namespace has been created by us. // namespace in case the namespace has been created by us.
func (n *Network) Remove(ctx context.Context, _ *NetworkNamespace, hypervisor Hypervisor) error { func (n *Network) Remove(ctx context.Context) error {
span, ctx := n.trace(ctx, "Remove") span, ctx := n.trace(ctx, "Remove")
defer span.End() defer span.End()

View File

@ -825,7 +825,7 @@ func (s *Sandbox) createNetwork(ctx context.Context) error {
// after vm is started. // after vm is started.
if s.factory == nil { if s.factory == nil {
// Add the network // Add the network
endpoints, err := s.network.Add(ctx, &s.config.NetworkConfig, s, false) endpoints, err := s.network.Add(ctx, s, false)
if err != nil { if err != nil {
return err return err
} }
@ -836,14 +836,14 @@ func (s *Sandbox) createNetwork(ctx context.Context) error {
} }
func (s *Sandbox) postCreatedNetwork(ctx context.Context) error { func (s *Sandbox) postCreatedNetwork(ctx context.Context) error {
return s.network.PostAdd(ctx, &s.networkNS, s.factory != nil) return s.network.PostAdd(ctx, s.factory != nil)
} }
func (s *Sandbox) removeNetwork(ctx context.Context) error { func (s *Sandbox) removeNetwork(ctx context.Context) error {
span, ctx := katatrace.Trace(ctx, s.Logger(), "removeNetwork", sandboxTracingTags, map[string]string{"sandbox_id": s.id}) span, ctx := katatrace.Trace(ctx, s.Logger(), "removeNetwork", sandboxTracingTags, map[string]string{"sandbox_id": s.id})
defer span.End() defer span.End()
return s.network.Remove(ctx, &s.networkNS, s.hypervisor) return s.network.Remove(ctx)
} }
func (s *Sandbox) generateNetInfo(inf *pbTypes.Interface) (NetworkInfo, error) { func (s *Sandbox) generateNetInfo(inf *pbTypes.Interface) (NetworkInfo, error) {
@ -1173,7 +1173,7 @@ func (s *Sandbox) startVM(ctx context.Context) (err error) {
} }
}() }()
if err := s.network.Run(ctx, s.networkNS.NetNsPath, func() error { if err := s.network.Run(ctx, func() error {
if s.factory != nil { if s.factory != nil {
vm, err := s.factory.GetVM(ctx, VMConfig{ vm, err := s.factory.GetVM(ctx, VMConfig{
HypervisorType: s.config.HypervisorType, HypervisorType: s.config.HypervisorType,
@ -1195,7 +1195,7 @@ func (s *Sandbox) startVM(ctx context.Context) (err error) {
// In case of vm factory, network interfaces are hotplugged // In case of vm factory, network interfaces are hotplugged
// after vm is started. // after vm is started.
if s.factory != nil { if s.factory != nil {
endpoints, err := s.network.Add(ctx, &s.config.NetworkConfig, s, true) endpoints, err := s.network.Add(ctx, s, true)
if err != nil { if err != nil {
return err return err
} }