Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
virtcontainers: Alias for pkg/types
Browse files Browse the repository at this point in the history
Since we're going to have both external and internal types packages, we
alias the external one as vcTypes. And the internal one will be usable
through the types namespace.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Samuel Ortiz committed Jan 8, 2019
1 parent 36c267a commit 3ab7d07
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 146 deletions.
10 changes: 5 additions & 5 deletions cli/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"os"

vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -152,7 +152,7 @@ func networkModifyCommand(ctx context.Context, containerID, input string, opType
}
switch opType {
case interfaceType:
var inf, resultingInf *types.Interface
var inf, resultingInf *vcTypes.Interface
if err = json.NewDecoder(f).Decode(&inf); err != nil {
return err
}
Expand All @@ -171,7 +171,7 @@ func networkModifyCommand(ctx context.Context, containerID, input string, opType
}
json.NewEncoder(output).Encode(resultingInf)
case routeType:
var routes, resultingRoutes []*types.Route
var routes, resultingRoutes []*vcTypes.Route
if err = json.NewDecoder(f).Decode(&routes); err != nil {
return err
}
Expand Down Expand Up @@ -209,15 +209,15 @@ func networkListCommand(ctx context.Context, containerID string, opType networkT

switch opType {
case interfaceType:
var interfaces []*types.Interface
var interfaces []*vcTypes.Interface
interfaces, err = vci.ListInterfaces(ctx, sandboxID)
if err != nil {
kataLog.WithField("existing-interfaces", fmt.Sprintf("%+v", interfaces)).
WithError(err).Error("list interfaces failed")
}
json.NewEncoder(file).Encode(interfaces)
case routeType:
var routes []*types.Route
var routes []*vcTypes.Route
routes, err = vci.ListRoutes(ctx, sandboxID)
if err != nil {
kataLog.WithField("resulting-routes", fmt.Sprintf("%+v", routes)).
Expand Down
12 changes: 6 additions & 6 deletions cli/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ import (
"testing"

vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/stretchr/testify/assert"
)

var (
testAddInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) {
testAddInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
return nil, nil
}
testRemoveInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *types.Interface) (*types.Interface, error) {
testRemoveInterfaceFuncReturnNil = func(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
return nil, nil
}
testListInterfacesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*types.Interface, error) {
testListInterfacesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) {
return nil, nil
}
testUpdateRoutsFuncReturnNil = func(ctx context.Context, sandboxID string, routes []*types.Route) ([]*types.Route, error) {
testUpdateRoutsFuncReturnNil = func(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) {
return nil, nil
}
testListRoutesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*types.Route, error) {
testListRoutesFuncReturnNil = func(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) {
return nil, nil
}
)
Expand Down
28 changes: 14 additions & 14 deletions netmon/netmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"

"github.com/kata-containers/runtime/pkg/signals"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/sirupsen/logrus"
lSyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -70,7 +70,7 @@ type netmon struct {
storagePath string
sharedFile string

netIfaces map[int]types.Interface
netIfaces map[int]vcTypes.Interface

linkUpdateCh chan netlink.LinkUpdate
linkDoneCh chan struct{}
Expand Down Expand Up @@ -151,7 +151,7 @@ func newNetmon(params netmonParams) (*netmon, error) {
netmonParams: params,
storagePath: filepath.Join(storageParentPath, params.sandboxID),
sharedFile: filepath.Join(storageParentPath, params.sandboxID, sharedFile),
netIfaces: make(map[int]types.Interface),
netIfaces: make(map[int]vcTypes.Interface),
linkUpdateCh: make(chan netlink.LinkUpdate),
linkDoneCh: make(chan struct{}),
rtUpdateCh: make(chan netlink.RouteUpdate),
Expand Down Expand Up @@ -259,13 +259,13 @@ func (n *netmon) listenNetlinkEvents() error {
// convertInterface converts a link and its IP addresses as defined by netlink
// package, into the Interface structure format expected by kata-runtime to
// describe an interface and its associated IP addresses.
func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []netlink.Addr) types.Interface {
func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []netlink.Addr) vcTypes.Interface {
if linkAttrs == nil {
netmonLog.Warn("Link attributes are nil")
return types.Interface{}
return vcTypes.Interface{}
}

var ipAddrs []*types.IPAddress
var ipAddrs []*vcTypes.IPAddress

for _, addr := range addrs {
if addr.IPNet == nil {
Expand All @@ -274,7 +274,7 @@ func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []net

netMask, _ := addr.Mask.Size()

ipAddr := &types.IPAddress{
ipAddr := &vcTypes.IPAddress{
Family: netlinkFamily,
Address: addr.IP.String(),
Mask: fmt.Sprintf("%d", netMask),
Expand All @@ -283,7 +283,7 @@ func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []net
ipAddrs = append(ipAddrs, ipAddr)
}

iface := types.Interface{
iface := vcTypes.Interface{
Device: linkAttrs.Name,
Name: linkAttrs.Name,
IPAddresses: ipAddrs,
Expand All @@ -300,8 +300,8 @@ func convertInterface(linkAttrs *netlink.LinkAttrs, linkType string, addrs []net
// convertRoutes converts a list of routes as defined by netlink package,
// into a list of Route structure format expected by kata-runtime to
// describe a set of routes.
func convertRoutes(netRoutes []netlink.Route) []types.Route {
var routes []types.Route
func convertRoutes(netRoutes []netlink.Route) []vcTypes.Route {
var routes []vcTypes.Route

// Ignore routes with IPv6 addresses as this is not supported
// by Kata yet.
Expand Down Expand Up @@ -335,7 +335,7 @@ func convertRoutes(netRoutes []netlink.Route) []types.Route {
dev = iface.Name
}

route := types.Route{
route := vcTypes.Route{
Dest: dst,
Gateway: gw,
Device: dev,
Expand Down Expand Up @@ -407,23 +407,23 @@ func (n *netmon) execKataCmd(subCmd string) error {
return os.Remove(n.sharedFile)
}

func (n *netmon) addInterfaceCLI(iface types.Interface) error {
func (n *netmon) addInterfaceCLI(iface vcTypes.Interface) error {
if err := n.storeDataToSend(iface); err != nil {
return err
}

return n.execKataCmd(kataCLIAddIfaceCmd)
}

func (n *netmon) delInterfaceCLI(iface types.Interface) error {
func (n *netmon) delInterfaceCLI(iface vcTypes.Interface) error {
if err := n.storeDataToSend(iface); err != nil {
return err
}

return n.execKataCmd(kataCLIDelIfaceCmd)
}

func (n *netmon) updateRoutesCLI(routes []types.Route) error {
func (n *netmon) updateRoutesCLI(routes []vcTypes.Route) error {
if err := n.storeDataToSend(routes); err != nil {
return err
}
Expand Down
36 changes: 18 additions & 18 deletions netmon/netmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"runtime"
"testing"

"github.com/kata-containers/runtime/virtcontainers/pkg/types"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -176,12 +176,12 @@ func TestConvertInterface(t *testing.T) {

linkType := "link_type_test"

expected := types.Interface{
expected := vcTypes.Interface{
Device: testIfaceName,
Name: testIfaceName,
Mtu: uint64(testMTU),
HwAddr: testHwAddr,
IPAddresses: []*types.IPAddress{
IPAddresses: []*vcTypes.IPAddress{
{
Family: netlinkFamily,
Address: testIPAddress,
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestConvertRoutes(t *testing.T) {
},
}

expected := []types.Route{
expected := []vcTypes.Route{
{
Dest: testIPAddress,
Gateway: testIPAddress,
Expand Down Expand Up @@ -245,7 +245,7 @@ func testSetupNetwork(t *testing.T) testTeardownNetwork {
}
}

func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, types.Interface) {
func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, vcTypes.Interface) {
hwAddr, err := net.ParseMAC(testHwAddr)
assert.Nil(t, err)

Expand All @@ -266,7 +266,7 @@ func testCreateDummyNetwork(t *testing.T, handler *netlink.Handle) (int, types.I
attrs := link.Attrs()
assert.NotNil(t, attrs)

iface := types.Interface{
iface := vcTypes.Interface{
Device: testIfaceName,
Name: testIfaceName,
Mtu: uint64(testMTU),
Expand All @@ -289,7 +289,7 @@ func TestScanNetwork(t *testing.T) {
idx, expected := testCreateDummyNetwork(t, handler)

n := &netmon{
netIfaces: make(map[int]types.Interface),
netIfaces: make(map[int]vcTypes.Interface),
netHandler: handler,
}

Expand All @@ -300,9 +300,9 @@ func TestScanNetwork(t *testing.T) {
}

func TestStoreDataToSend(t *testing.T) {
var got types.Interface
var got vcTypes.Interface

expected := types.Interface{
expected := vcTypes.Interface{
Device: testIfaceName,
Name: testIfaceName,
Mtu: uint64(testMTU),
Expand Down Expand Up @@ -399,15 +399,15 @@ func TestActionsCLI(t *testing.T) {
defer os.RemoveAll(testStorageParentPath)

// Test addInterfaceCLI
err = n.addInterfaceCLI(types.Interface{})
err = n.addInterfaceCLI(vcTypes.Interface{})
assert.Nil(t, err)

// Test delInterfaceCLI
err = n.delInterfaceCLI(types.Interface{})
err = n.delInterfaceCLI(vcTypes.Interface{})
assert.Nil(t, err)

// Test updateRoutesCLI
err = n.updateRoutesCLI([]types.Route{})
err = n.updateRoutesCLI([]vcTypes.Route{})
assert.Nil(t, err)

tearDownNetworkCb := testSetupNetwork(t)
Expand Down Expand Up @@ -465,8 +465,8 @@ func TestHandleRTMNewLink(t *testing.T) {
assert.Nil(t, err)

// Interface already exist in list
n.netIfaces = make(map[int]types.Interface)
n.netIfaces[testIfaceIndex] = types.Interface{}
n.netIfaces = make(map[int]vcTypes.Interface)
n.netIfaces[testIfaceIndex] = vcTypes.Interface{}
ev = netlink.LinkUpdate{
Link: &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Expand All @@ -479,7 +479,7 @@ func TestHandleRTMNewLink(t *testing.T) {
assert.Nil(t, err)

// Flags are not up and running
n.netIfaces = make(map[int]types.Interface)
n.netIfaces = make(map[int]vcTypes.Interface)
ev = netlink.LinkUpdate{
Link: &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Expand All @@ -492,7 +492,7 @@ func TestHandleRTMNewLink(t *testing.T) {
assert.Nil(t, err)

// Invalid link
n.netIfaces = make(map[int]types.Interface)
n.netIfaces = make(map[int]vcTypes.Interface)
ev = netlink.LinkUpdate{
Link: &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Expand Down Expand Up @@ -533,7 +533,7 @@ func TestHandleRTMDelLink(t *testing.T) {
assert.Nil(t, err)

// Interface does not exist in list
n.netIfaces = make(map[int]types.Interface)
n.netIfaces = make(map[int]vcTypes.Interface)
ev = netlink.LinkUpdate{
Link: &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Expand All @@ -548,7 +548,7 @@ func TestHandleRTMDelLink(t *testing.T) {

func TestHandleRTMNewRouteIfaceNotFound(t *testing.T) {
n := &netmon{
netIfaces: make(map[int]types.Interface),
netIfaces: make(map[int]vcTypes.Interface),
}

err := n.handleRTMNewRoute(netlink.RouteUpdate{})
Expand Down
10 changes: 5 additions & 5 deletions virtcontainers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/kata-containers/agent/protocols/grpc"
"github.com/kata-containers/runtime/virtcontainers/pkg/types"
vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
"github.com/mitchellh/mapstructure"
specs "github.com/opencontainers/runtime-spec/specs-go"
"golang.org/x/net/context"
Expand Down Expand Up @@ -234,16 +234,16 @@ type agent interface {
reseedRNG(data []byte) error

// updateInterface will tell the agent to update a nic for an existed Sandbox.
updateInterface(inf *types.Interface) (*types.Interface, error)
updateInterface(inf *vcTypes.Interface) (*vcTypes.Interface, error)

// listInterfaces will tell the agent to list interfaces of an existed Sandbox
listInterfaces() ([]*types.Interface, error)
listInterfaces() ([]*vcTypes.Interface, error)

// updateRoutes will tell the agent to update route table for an existed Sandbox.
updateRoutes(routes []*types.Route) ([]*types.Route, error)
updateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error)

// listRoutes will tell the agent to list routes of an existed Sandbox
listRoutes() ([]*types.Route, error)
listRoutes() ([]*vcTypes.Route, error)

// getGuestDetails will tell the agent to get some information of guest
getGuestDetails(*grpc.GuestDetailsRequest) (*grpc.GuestDetailsResponse, error)
Expand Down
Loading

0 comments on commit 3ab7d07

Please sign in to comment.