runtime: fix some comments and logs

This commit fix some conments/logs.
And add some logs for debug.

Fixes: #1947

Signed-off-by: bin <bin@hyper.sh>
This commit is contained in:
bin 2021-06-01 08:37:51 +08:00
parent c455d84571
commit b68334a1a8
4 changed files with 10 additions and 39 deletions

View File

@ -812,9 +812,7 @@ func (k *kataAgent) startSandbox(ctx context.Context, sandbox *Sandbox) error {
return err return err
} }
//
// Setup network interfaces and routes // Setup network interfaces and routes
//
interfaces, routes, neighs, err := generateVCNetworkStructures(sandbox.networkNS) interfaces, routes, neighs, err := generateVCNetworkStructures(sandbox.networkNS)
if err != nil { if err != nil {
return err return err

View File

@ -19,7 +19,6 @@ import (
"time" "time"
"github.com/containernetworking/plugins/pkg/ns" "github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/testutils"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
"github.com/vishvananda/netns" "github.com/vishvananda/netns"
@ -58,7 +57,7 @@ const (
NetXConnectInvalidModel NetXConnectInvalidModel
) )
//IsValid checks if a model is valid // IsValid checks if a model is valid
func (n NetInterworkingModel) IsValid() bool { func (n NetInterworkingModel) IsValid() bool {
return 0 <= int(n) && int(n) < int(NetXConnectInvalidModel) return 0 <= int(n) && int(n) < int(NetXConnectInvalidModel)
} }
@ -73,7 +72,7 @@ const (
noneNetModelStr = "none" noneNetModelStr = "none"
) )
//SetModel change the model string value // SetModel change the model string value
func (n *NetInterworkingModel) SetModel(modelName string) error { func (n *NetInterworkingModel) SetModel(modelName string) error {
switch modelName { switch modelName {
case defaultNetModelStr: case defaultNetModelStr:
@ -428,8 +427,10 @@ func xConnectVMNetwork(ctx context.Context, endpoint Endpoint, h hypervisor) err
switch netPair.NetInterworkingModel { switch netPair.NetInterworkingModel {
case NetXConnectMacVtapModel: case NetXConnectMacVtapModel:
networkLogger().Info("connect macvtap to VM network")
return tapNetworkPair(endpoint, queues, disableVhostNet) return tapNetworkPair(endpoint, queues, disableVhostNet)
case NetXConnectTCFilterModel: case NetXConnectTCFilterModel:
networkLogger().Info("connect TCFilter to VM network")
return setupTCFiltering(endpoint, queues, disableVhostNet) return setupTCFiltering(endpoint, queues, disableVhostNet)
default: default:
return fmt.Errorf("Invalid internetworking model") return fmt.Errorf("Invalid internetworking model")
@ -696,7 +697,7 @@ func setupTCFiltering(endpoint Endpoint, queues int, disableVhostNet bool) error
return nil return nil
} }
// addQdiscIngress creates a new qdisc for nwtwork interface with the specified network index // addQdiscIngress creates a new qdisc for network interface with the specified network index
// on "ingress". qdiscs normally don't work on ingress so this is really a special qdisc // on "ingress". qdiscs normally don't work on ingress so this is really a special qdisc
// that you can consider an "alternate root" for inbound packets. // that you can consider an "alternate root" for inbound packets.
// Handle for ingress qdisc defaults to "ffff:" // Handle for ingress qdisc defaults to "ffff:"
@ -882,15 +883,6 @@ func removeTCFiltering(endpoint Endpoint) error {
return nil return nil
} }
func createNetNS() (string, error) {
n, err := testutils.NewNS()
if err != nil {
return "", err
}
return n.Path(), nil
}
// doNetNS is free from any call to a go routine, and it calls // doNetNS is free from any call to a go routine, and it calls
// into runtime.LockOSThread(), meaning it won't be executed in a // into runtime.LockOSThread(), meaning it won't be executed in a
// different thread than the one expected by the caller. // different thread than the one expected by the caller.
@ -946,7 +938,6 @@ func deleteNetNS(netNSPath string) error {
} }
func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*pbTypes.Interface, []*pbTypes.Route, []*pbTypes.ARPNeighbor, error) { func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*pbTypes.Interface, []*pbTypes.Route, []*pbTypes.ARPNeighbor, error) {
if networkNS.NetNsPath == "" { if networkNS.NetNsPath == "" {
return nil, nil, nil, nil return nil, nil, nil, nil
} }
@ -956,7 +947,6 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*pbTypes.Interfa
var neighs []*pbTypes.ARPNeighbor var neighs []*pbTypes.ARPNeighbor
for _, endpoint := range networkNS.Endpoints { for _, endpoint := range networkNS.Endpoints {
var ipAddresses []*pbTypes.IPAddress var ipAddresses []*pbTypes.IPAddress
for _, addr := range endpoint.Properties().Addrs { for _, addr := range endpoint.Properties().Addrs {
// Skip localhost interface // Skip localhost interface
@ -1041,6 +1031,7 @@ func generateVCNetworkStructures(networkNS NetworkNamespace) ([]*pbTypes.Interfa
neighs = append(neighs, &n) neighs = append(neighs, &n)
} }
} }
return ifaces, routes, neighs, nil return ifaces, routes, neighs, nil
} }
@ -1238,8 +1229,10 @@ func createEndpoint(netInfo NetworkInfo, idx int, model NetInterworkingModel, li
} }
} }
} else if netInfo.Iface.Type == "veth" { } else if netInfo.Iface.Type == "veth" {
networkLogger().Info("veth interface found")
endpoint, err = createVethNetworkEndpoint(idx, netInfo.Iface.Name, model) endpoint, err = createVethNetworkEndpoint(idx, netInfo.Iface.Name, model)
} else if netInfo.Iface.Type == "ipvlan" { } else if netInfo.Iface.Type == "ipvlan" {
networkLogger().Info("ipvlan interface found")
endpoint, err = createIPVlanNetworkEndpoint(idx, netInfo.Iface.Name) endpoint, err = createIPVlanNetworkEndpoint(idx, netInfo.Iface.Name)
} else { } else {
return nil, fmt.Errorf("Unsupported network interface: %s", netInfo.Iface.Type) return nil, fmt.Errorf("Unsupported network interface: %s", netInfo.Iface.Type)
@ -1309,9 +1302,7 @@ func (n *Network) Add(ctx context.Context, config *NetworkConfig, s *Sandbox, ho
return err return err
} }
} }
} }
} }
return nil return nil
@ -1543,7 +1534,7 @@ func addIFBRedirecting(sourceIndex int, ifbIndex int) error {
return nil return nil
} }
// func addTxRateLmiter implements tx rate limiter to control network I/O outbound traffic // addTxRateLimiter implements tx rate limiter to control network I/O outbound traffic
// on VM level for hypervisors which don't implement rate limiter in itself, like qemu, etc. // on VM level for hypervisors which don't implement rate limiter in itself, like qemu, etc.
// We adopt different actions, based on different inter-networking models. // We adopt different actions, based on different inter-networking models.
// For tcfilters as inter-networking model, we simply apply htb qdisc discipline to the virtual netpair. // For tcfilters as inter-networking model, we simply apply htb qdisc discipline to the virtual netpair.

View File

@ -8,7 +8,6 @@ package virtcontainers
import ( import (
"fmt" "fmt"
"net" "net"
"os"
"reflect" "reflect"
"testing" "testing"
@ -20,23 +19,6 @@ import (
"github.com/vishvananda/netlink" "github.com/vishvananda/netlink"
) )
func TestCreateDeleteNetNS(t *testing.T) {
assert := assert.New(t)
if tc.NotValid(ktu.NeedRoot()) {
t.Skip(testDisabledAsNonRoot)
}
netNSPath, err := createNetNS()
assert.NoError(err)
assert.NotEmpty(netNSPath)
_, err = os.Stat(netNSPath)
assert.NoError(err)
err = deleteNetNS(netNSPath)
assert.NoError(err)
}
func TestGenerateInterfacesAndRoutes(t *testing.T) { func TestGenerateInterfacesAndRoutes(t *testing.T) {
// //
//Create a couple of addresses //Create a couple of addresses

View File

@ -1529,7 +1529,7 @@ func (s *Sandbox) Stop(ctx context.Context, force bool) error {
// shutdown console watcher if exists // shutdown console watcher if exists
if s.cw != nil { if s.cw != nil {
s.Logger().Debug("stop the sandbox") s.Logger().Debug("stop the console watcher")
s.cw.stop() s.cw.stop()
} }