mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-30 19:54:28 +01:00
runtime: consolidate types definition
We do not need the vc types translation for network data structures. Just use the protocol buffer definitions. Fixes: #415 Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
||||
"time"
|
||||
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"golang.org/x/net/context"
|
||||
@@ -182,16 +182,16 @@ type agent interface {
|
||||
reseedRNG(data []byte) error
|
||||
|
||||
// updateInterface will tell the agent to update a nic for an existed Sandbox.
|
||||
updateInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error)
|
||||
updateInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
|
||||
// listInterfaces will tell the agent to list interfaces of an existed Sandbox
|
||||
listInterfaces() ([]*vcTypes.Interface, error)
|
||||
listInterfaces() ([]*pbTypes.Interface, error)
|
||||
|
||||
// updateRoutes will tell the agent to update route table for an existed Sandbox.
|
||||
updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error)
|
||||
updateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error)
|
||||
|
||||
// listRoutes will tell the agent to list routes of an existed Sandbox
|
||||
listRoutes() ([]*vcTypes.Route, error)
|
||||
listRoutes() ([]*pbTypes.Route, error)
|
||||
|
||||
// getGuestDetails will tell the agent to get some information of guest
|
||||
getGuestDetails(*grpc.GuestDetailsRequest) (*grpc.GuestDetailsResponse, error)
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
deviceApi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
|
||||
deviceConfig "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/compatoci"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
@@ -798,7 +799,7 @@ func AddDevice(ctx context.Context, sandboxID string, info deviceConfig.DeviceIn
|
||||
return s.AddDevice(info)
|
||||
}
|
||||
|
||||
func toggleInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface, add bool) (*vcTypes.Interface, error) {
|
||||
func toggleInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface, add bool) (*pbTypes.Interface, error) {
|
||||
if sandboxID == "" {
|
||||
return nil, vcTypes.ErrNeedSandboxID
|
||||
}
|
||||
@@ -822,7 +823,7 @@ func toggleInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interfa
|
||||
}
|
||||
|
||||
// AddInterface is the virtcontainers add interface entry point.
|
||||
func AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func AddInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
span, ctx := trace(ctx, "AddInterface")
|
||||
defer span.Finish()
|
||||
|
||||
@@ -830,7 +831,7 @@ func AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface)
|
||||
}
|
||||
|
||||
// RemoveInterface is the virtcontainers remove interface entry point.
|
||||
func RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func RemoveInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
span, ctx := trace(ctx, "RemoveInterface")
|
||||
defer span.Finish()
|
||||
|
||||
@@ -838,7 +839,7 @@ func RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interfa
|
||||
}
|
||||
|
||||
// ListInterfaces is the virtcontainers list interfaces entry point.
|
||||
func ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) {
|
||||
func ListInterfaces(ctx context.Context, sandboxID string) ([]*pbTypes.Interface, error) {
|
||||
span, ctx := trace(ctx, "ListInterfaces")
|
||||
defer span.Finish()
|
||||
|
||||
@@ -861,7 +862,7 @@ func ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface
|
||||
}
|
||||
|
||||
// UpdateRoutes is the virtcontainers update routes entry point.
|
||||
func UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) {
|
||||
func UpdateRoutes(ctx context.Context, sandboxID string, routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
|
||||
span, ctx := trace(ctx, "UpdateRoutes")
|
||||
defer span.Finish()
|
||||
|
||||
@@ -884,7 +885,7 @@ func UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route
|
||||
}
|
||||
|
||||
// ListRoutes is the virtcontainers list routes entry point.
|
||||
func ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) {
|
||||
func ListRoutes(ctx context.Context, sandboxID string) ([]*pbTypes.Route, error) {
|
||||
span, ctx := trace(ctx, "ListRoutes")
|
||||
defer span.Finish()
|
||||
|
||||
|
||||
@@ -16,20 +16,20 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/cgroups"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/manager"
|
||||
vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
|
||||
"github.com/containerd/cgroups"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/manager"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
||||
)
|
||||
|
||||
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/major.h
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -65,11 +65,11 @@ type VCSandbox interface {
|
||||
|
||||
AddDevice(info config.DeviceInfo) (api.Device, error)
|
||||
|
||||
AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error)
|
||||
RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error)
|
||||
ListInterfaces() ([]*vcTypes.Interface, error)
|
||||
UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error)
|
||||
ListRoutes() ([]*vcTypes.Route, error)
|
||||
AddInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
RemoveInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
ListInterfaces() ([]*pbTypes.Interface, error)
|
||||
UpdateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error)
|
||||
ListRoutes() ([]*pbTypes.Route, error)
|
||||
|
||||
GetOOMEvent() (string, error)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
aTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
kataclient "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/client"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
|
||||
vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
|
||||
@@ -36,7 +36,6 @@ import (
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/vishvananda/netlink"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/sys/unix"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -565,10 +564,10 @@ func (k *kataAgent) exec(sandbox *Sandbox, c Container, cmd types.Cmd) (*Process
|
||||
return buildProcessFromExecID(req.ExecId)
|
||||
}
|
||||
|
||||
func (k *kataAgent) updateInterface(ifc *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func (k *kataAgent) updateInterface(ifc *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
// send update interface request
|
||||
ifcReq := &grpc.UpdateInterfaceRequest{
|
||||
Interface: k.convertToKataAgentInterface(ifc),
|
||||
Interface: ifc,
|
||||
}
|
||||
resultingInterface, err := k.sendReq(ifcReq)
|
||||
if err != nil {
|
||||
@@ -577,13 +576,13 @@ func (k *kataAgent) updateInterface(ifc *vcTypes.Interface) (*vcTypes.Interface,
|
||||
"resulting-interface": fmt.Sprintf("%+v", resultingInterface),
|
||||
}).WithError(err).Error("update interface request failed")
|
||||
}
|
||||
if resultInterface, ok := resultingInterface.(*vcTypes.Interface); ok {
|
||||
if resultInterface, ok := resultingInterface.(*pbTypes.Interface); ok {
|
||||
return resultInterface, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (k *kataAgent) updateInterfaces(interfaces []*vcTypes.Interface) error {
|
||||
func (k *kataAgent) updateInterfaces(interfaces []*pbTypes.Interface) error {
|
||||
for _, ifc := range interfaces {
|
||||
if _, err := k.updateInterface(ifc); err != nil {
|
||||
return err
|
||||
@@ -592,11 +591,11 @@ func (k *kataAgent) updateInterfaces(interfaces []*vcTypes.Interface) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *kataAgent) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) {
|
||||
func (k *kataAgent) updateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
|
||||
if routes != nil {
|
||||
routesReq := &grpc.UpdateRoutesRequest{
|
||||
Routes: &grpc.Routes{
|
||||
Routes: k.convertToKataAgentRoutes(routes),
|
||||
Routes: routes,
|
||||
},
|
||||
}
|
||||
resultingRoutes, err := k.sendReq(routesReq)
|
||||
@@ -608,18 +607,18 @@ func (k *kataAgent) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, err
|
||||
}
|
||||
resultRoutes, ok := resultingRoutes.(*grpc.Routes)
|
||||
if ok && resultRoutes != nil {
|
||||
return k.convertToRoutes(resultRoutes.Routes), err
|
||||
return resultRoutes.Routes, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (k *kataAgent) addARPNeighbors(neighs []*vcTypes.ARPNeighbor) error {
|
||||
func (k *kataAgent) addARPNeighbors(neighs []*pbTypes.ARPNeighbor) error {
|
||||
if neighs != nil {
|
||||
neighsReq := &grpc.AddARPNeighborsRequest{
|
||||
Neighbors: &grpc.ARPNeighbors{
|
||||
ARPNeighbors: k.convertToKataAgentNeighbors(neighs),
|
||||
ARPNeighbors: neighs,
|
||||
},
|
||||
}
|
||||
_, err := k.sendReq(neighsReq)
|
||||
@@ -639,7 +638,7 @@ func (k *kataAgent) addARPNeighbors(neighs []*vcTypes.ARPNeighbor) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *kataAgent) listInterfaces() ([]*vcTypes.Interface, error) {
|
||||
func (k *kataAgent) listInterfaces() ([]*pbTypes.Interface, error) {
|
||||
req := &grpc.ListInterfacesRequest{}
|
||||
resultingInterfaces, err := k.sendReq(req)
|
||||
if err != nil {
|
||||
@@ -647,12 +646,12 @@ func (k *kataAgent) listInterfaces() ([]*vcTypes.Interface, error) {
|
||||
}
|
||||
resultInterfaces, ok := resultingInterfaces.(*grpc.Interfaces)
|
||||
if ok {
|
||||
return k.convertToInterfaces(resultInterfaces.Interfaces), err
|
||||
return resultInterfaces.Interfaces, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (k *kataAgent) listRoutes() ([]*vcTypes.Route, error) {
|
||||
func (k *kataAgent) listRoutes() ([]*pbTypes.Route, error) {
|
||||
req := &grpc.ListRoutesRequest{}
|
||||
resultingRoutes, err := k.sendReq(req)
|
||||
if err != nil {
|
||||
@@ -660,7 +659,7 @@ func (k *kataAgent) listRoutes() ([]*vcTypes.Route, error) {
|
||||
}
|
||||
resultRoutes, ok := resultingRoutes.(*grpc.Routes)
|
||||
if ok {
|
||||
return k.convertToRoutes(resultRoutes.Routes), err
|
||||
return resultRoutes.Routes, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -2165,169 +2164,6 @@ func (k *kataAgent) setGuestDateTime(tv time.Time) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToKataAgentIPFamily(ipFamily int) aTypes.IPFamily {
|
||||
switch ipFamily {
|
||||
case netlink.FAMILY_V4:
|
||||
return aTypes.IPFamily_v4
|
||||
case netlink.FAMILY_V6:
|
||||
return aTypes.IPFamily_v6
|
||||
}
|
||||
|
||||
return aTypes.IPFamily_v4
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToIPFamily(ipFamily aTypes.IPFamily) int {
|
||||
switch ipFamily {
|
||||
case aTypes.IPFamily_v4:
|
||||
return netlink.FAMILY_V4
|
||||
case aTypes.IPFamily_v6:
|
||||
return netlink.FAMILY_V6
|
||||
}
|
||||
|
||||
return netlink.FAMILY_V4
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToKataAgentIPAddress(ipAddr *vcTypes.IPAddress) (aIPAddr *aTypes.IPAddress) {
|
||||
if ipAddr == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
aIPAddr = &aTypes.IPAddress{
|
||||
Family: k.convertToKataAgentIPFamily(ipAddr.Family),
|
||||
Address: ipAddr.Address,
|
||||
Mask: ipAddr.Mask,
|
||||
}
|
||||
|
||||
return aIPAddr
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToKataAgentIPAddresses(ipAddrs []*vcTypes.IPAddress) (aIPAddrs []*aTypes.IPAddress) {
|
||||
for _, ipAddr := range ipAddrs {
|
||||
if ipAddr == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
aIPAddr := k.convertToKataAgentIPAddress(ipAddr)
|
||||
aIPAddrs = append(aIPAddrs, aIPAddr)
|
||||
}
|
||||
|
||||
return aIPAddrs
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToIPAddresses(aIPAddrs []*aTypes.IPAddress) (ipAddrs []*vcTypes.IPAddress) {
|
||||
for _, aIPAddr := range aIPAddrs {
|
||||
if aIPAddr == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
ipAddr := &vcTypes.IPAddress{
|
||||
Family: k.convertToIPFamily(aIPAddr.Family),
|
||||
Address: aIPAddr.Address,
|
||||
Mask: aIPAddr.Mask,
|
||||
}
|
||||
|
||||
ipAddrs = append(ipAddrs, ipAddr)
|
||||
}
|
||||
|
||||
return ipAddrs
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToKataAgentInterface(iface *vcTypes.Interface) *aTypes.Interface {
|
||||
if iface == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &aTypes.Interface{
|
||||
Device: iface.Device,
|
||||
Name: iface.Name,
|
||||
IPAddresses: k.convertToKataAgentIPAddresses(iface.IPAddresses),
|
||||
Mtu: iface.Mtu,
|
||||
RawFlags: iface.RawFlags,
|
||||
HwAddr: iface.HwAddr,
|
||||
PciAddr: iface.PciAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToInterfaces(aIfaces []*aTypes.Interface) (ifaces []*vcTypes.Interface) {
|
||||
for _, aIface := range aIfaces {
|
||||
if aIface == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
iface := &vcTypes.Interface{
|
||||
Device: aIface.Device,
|
||||
Name: aIface.Name,
|
||||
IPAddresses: k.convertToIPAddresses(aIface.IPAddresses),
|
||||
Mtu: aIface.Mtu,
|
||||
HwAddr: aIface.HwAddr,
|
||||
PciAddr: aIface.PciAddr,
|
||||
}
|
||||
|
||||
ifaces = append(ifaces, iface)
|
||||
}
|
||||
|
||||
return ifaces
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToKataAgentRoutes(routes []*vcTypes.Route) (aRoutes []*aTypes.Route) {
|
||||
for _, route := range routes {
|
||||
if route == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
aRoute := &aTypes.Route{
|
||||
Dest: route.Dest,
|
||||
Gateway: route.Gateway,
|
||||
Device: route.Device,
|
||||
Source: route.Source,
|
||||
Scope: route.Scope,
|
||||
}
|
||||
|
||||
aRoutes = append(aRoutes, aRoute)
|
||||
}
|
||||
|
||||
return aRoutes
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToKataAgentNeighbors(neighs []*vcTypes.ARPNeighbor) (aNeighs []*aTypes.ARPNeighbor) {
|
||||
for _, neigh := range neighs {
|
||||
if neigh == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
aNeigh := &aTypes.ARPNeighbor{
|
||||
ToIPAddress: k.convertToKataAgentIPAddress(neigh.ToIPAddress),
|
||||
Device: neigh.Device,
|
||||
State: int32(neigh.State),
|
||||
Lladdr: neigh.LLAddr,
|
||||
}
|
||||
|
||||
aNeighs = append(aNeighs, aNeigh)
|
||||
}
|
||||
|
||||
return aNeighs
|
||||
}
|
||||
|
||||
func (k *kataAgent) convertToRoutes(aRoutes []*aTypes.Route) (routes []*vcTypes.Route) {
|
||||
for _, aRoute := range aRoutes {
|
||||
if aRoute == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
route := &vcTypes.Route{
|
||||
Dest: aRoute.Dest,
|
||||
Gateway: aRoute.Gateway,
|
||||
Device: aRoute.Device,
|
||||
Source: aRoute.Source,
|
||||
Scope: aRoute.Scope,
|
||||
}
|
||||
|
||||
routes = append(routes, route)
|
||||
}
|
||||
|
||||
return routes
|
||||
}
|
||||
|
||||
func (k *kataAgent) copyFile(src, dst string) error {
|
||||
var st unix.Stat_t
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ import (
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/manager"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist"
|
||||
aTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
pb "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
|
||||
vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
)
|
||||
|
||||
@@ -1062,7 +1062,7 @@ func TestAgentNetworkOperation(t *testing.T) {
|
||||
_, err = k.listInterfaces()
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.updateRoutes([]*vcTypes.Route{})
|
||||
_, err = k.updateRoutes([]*pbTypes.Route{})
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.listRoutes()
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"time"
|
||||
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"golang.org/x/net/context"
|
||||
@@ -111,22 +111,22 @@ func (n *mockAgent) onlineCPUMem(cpus uint32, cpuOnly bool) error {
|
||||
}
|
||||
|
||||
// updateInterface is the Noop agent Interface update implementation. It does nothing.
|
||||
func (n *mockAgent) updateInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func (n *mockAgent) updateInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// listInterfaces is the Noop agent Interfaces list implementation. It does nothing.
|
||||
func (n *mockAgent) listInterfaces() ([]*vcTypes.Interface, error) {
|
||||
func (n *mockAgent) listInterfaces() ([]*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// updateRoutes is the Noop agent Routes update implementation. It does nothing.
|
||||
func (n *mockAgent) updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) {
|
||||
func (n *mockAgent) updateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// listRoutes is the Noop agent Routes list implementation. It does nothing.
|
||||
func (n *mockAgent) listRoutes() ([]*vcTypes.Route, error) {
|
||||
func (n *mockAgent) listRoutes() ([]*pbTypes.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ import (
|
||||
"github.com/vishvananda/netns"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/uuid"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
)
|
||||
@@ -943,19 +943,19 @@ func deleteNetNS(netNSPath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interface, []*vcTypes.Route, []*vcTypes.ARPNeighbor, error) {
|
||||
func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*pbTypes.Interface, []*pbTypes.Route, []*pbTypes.ARPNeighbor, error) {
|
||||
|
||||
if networkNS.NetNsPath == "" {
|
||||
return nil, nil, nil, nil
|
||||
}
|
||||
|
||||
var routes []*vcTypes.Route
|
||||
var ifaces []*vcTypes.Interface
|
||||
var neighs []*vcTypes.ARPNeighbor
|
||||
var routes []*pbTypes.Route
|
||||
var ifaces []*pbTypes.Interface
|
||||
var neighs []*pbTypes.ARPNeighbor
|
||||
|
||||
for _, endpoint := range networkNS.Endpoints {
|
||||
|
||||
var ipAddresses []*vcTypes.IPAddress
|
||||
var ipAddresses []*pbTypes.IPAddress
|
||||
for _, addr := range endpoint.Properties().Addrs {
|
||||
// Skip localhost interface
|
||||
if addr.IP.IsLoopback() {
|
||||
@@ -963,19 +963,19 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interfa
|
||||
}
|
||||
|
||||
netMask, _ := addr.Mask.Size()
|
||||
ipAddress := vcTypes.IPAddress{
|
||||
Family: netlink.FAMILY_V4,
|
||||
ipAddress := pbTypes.IPAddress{
|
||||
Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4),
|
||||
Address: addr.IP.String(),
|
||||
Mask: fmt.Sprintf("%d", netMask),
|
||||
}
|
||||
|
||||
if addr.IP.To4() == nil {
|
||||
ipAddress.Family = netlink.FAMILY_V6
|
||||
ipAddress.Family = utils.ConvertNetlinkFamily(netlink.FAMILY_V6)
|
||||
}
|
||||
ipAddresses = append(ipAddresses, &ipAddress)
|
||||
}
|
||||
noarp := endpoint.Properties().Iface.RawFlags & unix.IFF_NOARP
|
||||
ifc := vcTypes.Interface{
|
||||
ifc := pbTypes.Interface{
|
||||
IPAddresses: ipAddresses,
|
||||
Device: endpoint.Name(),
|
||||
Name: endpoint.Name(),
|
||||
@@ -988,7 +988,7 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interfa
|
||||
ifaces = append(ifaces, &ifc)
|
||||
|
||||
for _, route := range endpoint.Properties().Routes {
|
||||
var r vcTypes.Route
|
||||
var r pbTypes.Route
|
||||
|
||||
if route.Protocol == unix.RTPROT_KERNEL {
|
||||
continue
|
||||
@@ -1013,7 +1013,7 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interfa
|
||||
}
|
||||
|
||||
for _, neigh := range endpoint.Properties().Neighbors {
|
||||
var n vcTypes.ARPNeighbor
|
||||
var n pbTypes.ARPNeighbor
|
||||
|
||||
// We add only static ARP entries
|
||||
if neigh.State != netlink.NUD_PERMANENT {
|
||||
@@ -1021,15 +1021,15 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*vcTypes.Interfa
|
||||
}
|
||||
|
||||
n.Device = endpoint.Name()
|
||||
n.State = neigh.State
|
||||
n.Flags = neigh.Flags
|
||||
n.State = int32(neigh.State)
|
||||
n.Flags = int32(neigh.Flags)
|
||||
|
||||
if neigh.HardwareAddr != nil {
|
||||
n.LLAddr = neigh.HardwareAddr.String()
|
||||
n.Lladdr = neigh.HardwareAddr.String()
|
||||
}
|
||||
|
||||
n.ToIPAddress = &vcTypes.IPAddress{
|
||||
Family: netlink.FAMILY_V4,
|
||||
n.ToIPAddress = &pbTypes.IPAddress{
|
||||
Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4),
|
||||
Address: neigh.IP.String(),
|
||||
}
|
||||
if neigh.IP.To4() == nil {
|
||||
|
||||
@@ -14,7 +14,8 @@ import (
|
||||
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
@@ -96,29 +97,29 @@ func TestGenerateInterfacesAndRoutes(t *testing.T) {
|
||||
//
|
||||
// Build expected results:
|
||||
//
|
||||
expectedAddresses := []*vcTypes.IPAddress{
|
||||
{Family: netlink.FAMILY_V4, Address: "172.17.0.2", Mask: "16"},
|
||||
{Family: netlink.FAMILY_V4, Address: "182.17.0.2", Mask: "16"},
|
||||
{Family: netlink.FAMILY_V6, Address: "2001:db8:1::242:ac11:2", Mask: "64"},
|
||||
expectedAddresses := []*pbTypes.IPAddress{
|
||||
{Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4), Address: "172.17.0.2", Mask: "16"},
|
||||
{Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4), Address: "182.17.0.2", Mask: "16"},
|
||||
{Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V6), Address: "2001:db8:1::242:ac11:2", Mask: "64"},
|
||||
}
|
||||
|
||||
expectedInterfaces := []*vcTypes.Interface{
|
||||
expectedInterfaces := []*pbTypes.Interface{
|
||||
{Device: "eth0", Name: "eth0", IPAddresses: expectedAddresses, Mtu: 1500, HwAddr: "02:00:ca:fe:00:04"},
|
||||
}
|
||||
|
||||
expectedRoutes := []*vcTypes.Route{
|
||||
expectedRoutes := []*pbTypes.Route{
|
||||
{Dest: "", Gateway: "172.17.0.1", Device: "eth0", Source: "", Scope: uint32(254)},
|
||||
{Dest: "172.17.0.0/16", Gateway: "172.17.0.1", Device: "eth0", Source: "172.17.0.2"},
|
||||
{Dest: "2001:db8:1::/64", Gateway: "", Device: "eth0", Source: ""},
|
||||
{Dest: "", Gateway: "2001:db8:1::1", Device: "eth0", Source: ""},
|
||||
}
|
||||
|
||||
expectedNeighs := []*vcTypes.ARPNeighbor{
|
||||
expectedNeighs := []*pbTypes.ARPNeighbor{
|
||||
{
|
||||
Device: "eth0",
|
||||
State: netlink.NUD_PERMANENT,
|
||||
LLAddr: "6a:92:3a:59:70:aa",
|
||||
ToIPAddress: &vcTypes.IPAddress{Address: "192.168.0.101", Family: netlink.FAMILY_V4},
|
||||
Lladdr: "6a:92:3a:59:70:aa",
|
||||
ToIPAddress: &pbTypes.IPAddress{Address: "192.168.0.101", Family: utils.ConvertNetlinkFamily(netlink.FAMILY_V4)},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
// Copyright 2018 Intel Corporation.
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package types
|
||||
|
||||
// IPAddress describes an IP address.
|
||||
type IPAddress struct {
|
||||
Family int
|
||||
Address string
|
||||
Mask string
|
||||
}
|
||||
|
||||
// Interface describes a network interface.
|
||||
type Interface struct {
|
||||
Device string
|
||||
Name string
|
||||
IPAddresses []*IPAddress
|
||||
Mtu uint64
|
||||
RawFlags uint32
|
||||
HwAddr string
|
||||
// pciAddr is the PCI address in the format "bridgeAddr/deviceAddr".
|
||||
// Here, bridgeAddr is the address at which the bridge is attached on the root bus,
|
||||
// while deviceAddr is the address at which the network device is attached on the bridge.
|
||||
PciAddr string
|
||||
// LinkType defines the type of interface described by this structure.
|
||||
// The expected values are the one that are defined by the netlink
|
||||
// library, regarding each type of link. Here is a non exhaustive
|
||||
// list: "veth", "macvtap", "vlan", "macvlan", "tap", ...
|
||||
LinkType string
|
||||
}
|
||||
|
||||
// Route describes a network route.
|
||||
type Route struct {
|
||||
Dest string
|
||||
Gateway string
|
||||
Device string
|
||||
Source string
|
||||
Scope uint32
|
||||
}
|
||||
|
||||
type ARPNeighbor struct {
|
||||
ToIPAddress *IPAddress
|
||||
Device string
|
||||
LLAddr string
|
||||
State int
|
||||
Flags int
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -246,7 +246,7 @@ func (m *VCMock) AddDevice(ctx context.Context, sandboxID string, info config.De
|
||||
}
|
||||
|
||||
// AddInterface implements the VC function of the same name.
|
||||
func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
if m.AddInterfaceFunc != nil {
|
||||
return m.AddInterfaceFunc(ctx, sandboxID, inf)
|
||||
}
|
||||
@@ -255,7 +255,7 @@ func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *vcType
|
||||
}
|
||||
|
||||
// RemoveInterface implements the VC function of the same name.
|
||||
func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
if m.RemoveInterfaceFunc != nil {
|
||||
return m.RemoveInterfaceFunc(ctx, sandboxID, inf)
|
||||
}
|
||||
@@ -264,7 +264,7 @@ func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *vcT
|
||||
}
|
||||
|
||||
// ListInterfaces implements the VC function of the same name.
|
||||
func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) {
|
||||
func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*pbTypes.Interface, error) {
|
||||
if m.ListInterfacesFunc != nil {
|
||||
return m.ListInterfacesFunc(ctx, sandboxID)
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTyp
|
||||
}
|
||||
|
||||
// UpdateRoutes implements the VC function of the same name.
|
||||
func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) {
|
||||
func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
|
||||
if m.UpdateRoutesFunc != nil {
|
||||
return m.UpdateRoutesFunc(ctx, sandboxID, routes)
|
||||
}
|
||||
@@ -282,7 +282,7 @@ func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*v
|
||||
}
|
||||
|
||||
// ListRoutes implements the VC function of the same name.
|
||||
func (m *VCMock) ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) {
|
||||
func (m *VCMock) ListRoutes(ctx context.Context, sandboxID string) ([]*pbTypes.Route, error) {
|
||||
if m.ListRoutesFunc != nil {
|
||||
return m.ListRoutesFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/factory"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -694,7 +694,7 @@ func TestVCMockAddInterface(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.AddInterfaceFunc = func(ctx context.Context, sid string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
m.AddInterfaceFunc = func(ctx context.Context, sid string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -721,7 +721,7 @@ func TestVCMockRemoveInterface(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.RemoveInterfaceFunc = func(ctx context.Context, sid string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
m.RemoveInterfaceFunc = func(ctx context.Context, sid string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -748,7 +748,7 @@ func TestVCMockListInterfaces(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ListInterfacesFunc = func(ctx context.Context, sid string) ([]*vcTypes.Interface, error) {
|
||||
m.ListInterfacesFunc = func(ctx context.Context, sid string) ([]*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -775,7 +775,7 @@ func TestVCMockUpdateRoutes(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.UpdateRoutesFunc = func(ctx context.Context, sid string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) {
|
||||
m.UpdateRoutesFunc = func(ctx context.Context, sid string, routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -802,7 +802,7 @@ func TestVCMockListRoutes(t *testing.T) {
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ListRoutesFunc = func(ctx context.Context, sid string) ([]*vcTypes.Route, error) {
|
||||
m.ListRoutesFunc = func(ctx context.Context, sid string) ([]*pbTypes.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
@@ -196,27 +196,27 @@ func (s *Sandbox) AddDevice(info config.DeviceInfo) (api.Device, error) {
|
||||
}
|
||||
|
||||
// AddInterface implements the VCSandbox function of the same name.
|
||||
func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func (s *Sandbox) AddInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// RemoveInterface implements the VCSandbox function of the same name.
|
||||
func (s *Sandbox) RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func (s *Sandbox) RemoveInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ListInterfaces implements the VCSandbox function of the same name.
|
||||
func (s *Sandbox) ListInterfaces() ([]*vcTypes.Interface, error) {
|
||||
func (s *Sandbox) ListInterfaces() ([]*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// UpdateRoutes implements the VCSandbox function of the same name.
|
||||
func (s *Sandbox) UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) {
|
||||
func (s *Sandbox) UpdateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ListRoutes implements the VCSandbox function of the same name.
|
||||
func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) {
|
||||
func (s *Sandbox) ListRoutes() ([]*pbTypes.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -59,11 +59,11 @@ type Sandbox struct {
|
||||
WinsizeProcessFunc func(containerID, processID string, height, width uint32) error
|
||||
IOStreamFunc func(containerID, processID string) (io.WriteCloser, io.Reader, io.Reader, error)
|
||||
AddDeviceFunc func(info config.DeviceInfo) (api.Device, error)
|
||||
AddInterfaceFunc func(inf *vcTypes.Interface) (*vcTypes.Interface, error)
|
||||
RemoveInterfaceFunc func(inf *vcTypes.Interface) (*vcTypes.Interface, error)
|
||||
ListInterfacesFunc func() ([]*vcTypes.Interface, error)
|
||||
UpdateRoutesFunc func(routes []*vcTypes.Route) ([]*vcTypes.Route, error)
|
||||
ListRoutesFunc func() ([]*vcTypes.Route, error)
|
||||
AddInterfaceFunc func(inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
RemoveInterfaceFunc func(inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
ListInterfacesFunc func() ([]*pbTypes.Interface, error)
|
||||
UpdateRoutesFunc func(routes []*pbTypes.Route) ([]*pbTypes.Route, error)
|
||||
ListRoutesFunc func() ([]*pbTypes.Route, error)
|
||||
UpdateRuntimeMetricsFunc func() error
|
||||
GetAgentMetricsFunc func() (string, error)
|
||||
StatsFunc func() (vc.SandboxStats, error)
|
||||
@@ -111,10 +111,10 @@ type VCMock struct {
|
||||
|
||||
AddDeviceFunc func(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error)
|
||||
|
||||
AddInterfaceFunc func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error)
|
||||
RemoveInterfaceFunc func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error)
|
||||
ListInterfacesFunc func(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error)
|
||||
UpdateRoutesFunc func(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error)
|
||||
ListRoutesFunc func(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error)
|
||||
AddInterfaceFunc func(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
RemoveInterfaceFunc func(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
ListInterfacesFunc func(ctx context.Context, sandboxID string) ([]*pbTypes.Interface, error)
|
||||
UpdateRoutesFunc func(ctx context.Context, sandboxID string, routes []*pbTypes.Route) ([]*pbTypes.Route, error)
|
||||
ListRoutesFunc func(ctx context.Context, sandboxID string) ([]*pbTypes.Route, error)
|
||||
CleanupContainerFunc func(ctx context.Context, sandboxID, containerID string, force bool) error
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
exp "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/experimental"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist"
|
||||
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
|
||||
vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
|
||||
@@ -846,7 +847,7 @@ func (s *Sandbox) removeNetwork() error {
|
||||
return s.network.Remove(s.ctx, &s.networkNS, s.hypervisor)
|
||||
}
|
||||
|
||||
func (s *Sandbox) generateNetInfo(inf *vcTypes.Interface) (NetworkInfo, error) {
|
||||
func (s *Sandbox) generateNetInfo(inf *pbTypes.Interface) (NetworkInfo, error) {
|
||||
hw, err := net.ParseMAC(inf.HwAddr)
|
||||
if err != nil {
|
||||
return NetworkInfo{}, err
|
||||
@@ -870,14 +871,14 @@ func (s *Sandbox) generateNetInfo(inf *vcTypes.Interface) (NetworkInfo, error) {
|
||||
HardwareAddr: hw,
|
||||
MTU: int(inf.Mtu),
|
||||
},
|
||||
Type: inf.LinkType,
|
||||
Type: inf.Type,
|
||||
},
|
||||
Addrs: addrs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// AddInterface adds new nic to the sandbox.
|
||||
func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func (s *Sandbox) AddInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
netInfo, err := s.generateNetInfo(inf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -908,7 +909,7 @@ func (s *Sandbox) AddInterface(inf *vcTypes.Interface) (*vcTypes.Interface, erro
|
||||
}
|
||||
|
||||
// RemoveInterface removes a nic of the sandbox.
|
||||
func (s *Sandbox) RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error) {
|
||||
func (s *Sandbox) RemoveInterface(inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
for i, endpoint := range s.networkNS.Endpoints {
|
||||
if endpoint.HardwareAddr() == inf.HwAddr {
|
||||
s.Logger().WithField("endpoint-type", endpoint.Type()).Info("Hot detaching endpoint")
|
||||
@@ -928,17 +929,17 @@ func (s *Sandbox) RemoveInterface(inf *vcTypes.Interface) (*vcTypes.Interface, e
|
||||
}
|
||||
|
||||
// ListInterfaces lists all nics and their configurations in the sandbox.
|
||||
func (s *Sandbox) ListInterfaces() ([]*vcTypes.Interface, error) {
|
||||
func (s *Sandbox) ListInterfaces() ([]*pbTypes.Interface, error) {
|
||||
return s.agent.listInterfaces()
|
||||
}
|
||||
|
||||
// UpdateRoutes updates the sandbox route table (e.g. for portmapping support).
|
||||
func (s *Sandbox) UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) {
|
||||
func (s *Sandbox) UpdateRoutes(routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
|
||||
return s.agent.updateRoutes(routes)
|
||||
}
|
||||
|
||||
// ListRoutes lists all routes and their configurations in the sandbox.
|
||||
func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) {
|
||||
func (s *Sandbox) ListRoutes() ([]*pbTypes.Route, error) {
|
||||
return s.agent.listRoutes()
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
)
|
||||
|
||||
const cpBinaryName = "cp"
|
||||
@@ -318,3 +322,14 @@ func (p *ProgramLogger) StartLogger(output io.ReadCloser) error {
|
||||
func (p ProgramLogger) String() string {
|
||||
return p.cmd.Path
|
||||
}
|
||||
|
||||
func ConvertNetlinkFamily(netlinkFamily int32) pbTypes.IPFamily {
|
||||
switch netlinkFamily {
|
||||
case netlink.FAMILY_V6:
|
||||
return pbTypes.IPFamily_v6
|
||||
case netlink.FAMILY_V4:
|
||||
fallthrough
|
||||
default:
|
||||
return pbTypes.IPFamily_v4
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user