mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 15:02:45 +00:00
network: Fix network attach for ipvlan and macvlan
We used the approach of cold-plugging network interface for pre-shimv2 support for docker.Since the hotplug approach was not required, we never really got to implementing hotplug support for certain network endpoints, ipvlan and macvlan being among them. Since moving to shimv2 interface as the default for runtime, we switched to hotplugging the network interface for supporting docker and nerdctl. This was done for veth endpoints only. Implement the hot-attach apis for ipvlan and macvlan as well to support ipvlan and macvlan networks with docker and nerdctl. Fixes: #8333 Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
4ede63fa4d
commit
f53f86884f
@ -125,14 +125,42 @@ func (endpoint *IPVlanEndpoint) Detach(ctx context.Context, netNsCreated bool, n
|
||||
})
|
||||
}
|
||||
|
||||
// HotAttach for ipvlan endpoint not supported yet
|
||||
func (endpoint *IPVlanEndpoint) HotAttach(ctx context.Context, h Hypervisor) error {
|
||||
return fmt.Errorf("IPVlanEndpoint does not support Hot attach")
|
||||
span, ctx := ipvlanTrace(ctx, "HotAttach", endpoint)
|
||||
defer span.End()
|
||||
|
||||
if err := xConnectVMNetwork(ctx, endpoint, h); err != nil {
|
||||
networkLogger().WithError(err).Error("Error bridging ipvlan ep")
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := h.HotplugAddDevice(ctx, endpoint, NetDev); err != nil {
|
||||
networkLogger().WithError(err).Error("Error hotplugging ipvlan ep")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HotDetach for ipvlan endpoint not supported yet
|
||||
func (endpoint *IPVlanEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error {
|
||||
return fmt.Errorf("IPVlanEndpoint does not support Hot detach")
|
||||
if !netNsCreated {
|
||||
return nil
|
||||
}
|
||||
|
||||
span, ctx := ipvlanTrace(ctx, "HotDetach", endpoint)
|
||||
defer span.End()
|
||||
|
||||
if err := doNetNS(netNsPath, func(_ ns.NetNS) error {
|
||||
return xDisconnectVMNetwork(ctx, endpoint)
|
||||
}); err != nil {
|
||||
networkLogger().WithError(err).Warn("Error un-bridging ipvlan ep")
|
||||
}
|
||||
|
||||
if _, err := h.HotplugRemoveDevice(ctx, endpoint, NetDev); err != nil {
|
||||
networkLogger().WithError(err).Error("Error detach ipvlan ep")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (endpoint *IPVlanEndpoint) save() persistapi.NetworkEndpoint {
|
||||
|
@ -122,14 +122,42 @@ func (endpoint *MacvlanEndpoint) Detach(ctx context.Context, netNsCreated bool,
|
||||
})
|
||||
}
|
||||
|
||||
// HotAttach for bridged macvlan endpoint not supported yet
|
||||
func (endpoint *MacvlanEndpoint) HotAttach(ctx context.Context, h Hypervisor) error {
|
||||
return fmt.Errorf("MacvlanEndpoint does not support Hot attach")
|
||||
span, ctx := macvlanTrace(ctx, "HotAttach", endpoint)
|
||||
defer span.End()
|
||||
|
||||
if err := xConnectVMNetwork(ctx, endpoint, h); err != nil {
|
||||
networkLogger().WithError(err).Error("Error bridging macvlan ep")
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := h.HotplugAddDevice(ctx, endpoint, NetDev); err != nil {
|
||||
networkLogger().WithError(err).Error("Error hotplugging macvlan ep")
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HotDetach for bridged macvlan endpoint not supported yet
|
||||
func (endpoint *MacvlanEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error {
|
||||
return fmt.Errorf("MacvlanEndpoint does not support Hot detach")
|
||||
if !netNsCreated {
|
||||
return nil
|
||||
}
|
||||
|
||||
span, ctx := macvlanTrace(ctx, "HotDetach", endpoint)
|
||||
defer span.End()
|
||||
|
||||
if err := doNetNS(netNsPath, func(_ ns.NetNS) error {
|
||||
return xDisconnectVMNetwork(ctx, endpoint)
|
||||
}); err != nil {
|
||||
networkLogger().WithError(err).Warn("Error un-bridging macvlan ep")
|
||||
}
|
||||
|
||||
if _, err := h.HotplugRemoveDevice(ctx, endpoint, NetDev); err != nil {
|
||||
networkLogger().WithError(err).Error("Error detach macvlan ep")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (endpoint *MacvlanEndpoint) save() persistapi.NetworkEndpoint {
|
||||
|
Loading…
Reference in New Issue
Block a user