virtcontainers: Remove the Network PostAdd method

It's used once by the sandbox code and can be implemented directly
there.

Signed-off-by: Samuel Ortiz <s.ortiz@apple.com>
This commit is contained in:
Samuel Ortiz 2021-11-09 01:45:13 +00:00 committed by Samuel Ortiz
parent e0b264430d
commit c67109a251
3 changed files with 21 additions and 30 deletions

View File

@ -211,9 +211,6 @@ type Network interface {
// RemoveEndpoint removes one single endpoint from the sandbox's network. // RemoveEndpoint removes one single endpoint from the sandbox's network.
RemoveEndpoint(context.Context, *Sandbox, int, bool) error RemoveEndpoint(context.Context, *Sandbox, int, bool) error
// PostAdd is a post networking endpoint addition hook.
PostAdd(context.Context, bool) error
// Run runs a callback in a sandbox's network. // Run runs a callback in a sandbox's network.
Run(context.Context, func() error) error Run(context.Context, func() error) error

View File

@ -339,32 +339,6 @@ func (n *LinuxNetwork) Add(ctx context.Context, s *Sandbox, hotplug bool) error
return nil return nil
} }
func (n *LinuxNetwork) PostAdd(ctx context.Context, hotplug bool) error {
if hotplug {
return nil
}
if n.eps == nil {
return nil
}
endpoints := n.eps
for _, endpoint := range endpoints {
netPair := endpoint.NetworkPair()
if netPair == nil {
continue
}
if netPair.VhostFds != nil {
for _, VhostFd := range netPair.VhostFds {
VhostFd.Close()
}
}
}
return nil
}
// 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 *LinuxNetwork) Remove(ctx context.Context) error { func (n *LinuxNetwork) Remove(ctx context.Context) error {

View File

@ -826,7 +826,27 @@ 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.factory != nil) if s.factory != nil {
return nil
}
if s.network.Endpoints() == nil {
return nil
}
for _, endpoint := range s.network.Endpoints() {
netPair := endpoint.NetworkPair()
if netPair == nil {
continue
}
if netPair.VhostFds != nil {
for _, VhostFd := range netPair.VhostFds {
VhostFd.Close()
}
}
}
return nil
} }
func (s *Sandbox) removeNetwork(ctx context.Context) error { func (s *Sandbox) removeNetwork(ctx context.Context) error {