Ensure the bandwith plugin chooses the host veth device

When chained with a plugin that returns multiple devices, the bandwidth
plugin chooses the host veth device.

Signed-off-by: Tyler Schultz <tschultz@pivotal.io>
This commit is contained in:
Aidan Obley
2018-03-12 15:08:53 -07:00
committed by Tyler Schultz
parent d5bdfe4cbd
commit d2f6472474
6 changed files with 261 additions and 66 deletions

View File

@ -17,7 +17,6 @@ package main
import (
"crypto/sha1"
"encoding/json"
"errors"
"fmt"
"github.com/containernetworking/cni/pkg/skel"
@ -25,7 +24,9 @@ import (
"github.com/containernetworking/cni/pkg/types/current"
"github.com/containernetworking/cni/pkg/version"
"github.com/containernetworking/plugins/pkg/ip"
"github.com/vishvananda/netlink"
"errors"
)
type PluginConf struct {
@ -112,15 +113,16 @@ func getMTU(deviceName string) (int, error) {
}
func getHostInterface(interfaces []*current.Interface) (*current.Interface, error) {
for _, prevIface := range interfaces {
if prevIface.Sandbox != "" {
continue
var err error
for _, iface := range interfaces {
if iface.Sandbox == "" { // host interface
_, _, err = ip.GetVethPeerIfindex(iface.Name)
if err == nil {
return iface, err
}
}
return prevIface, nil
}
return nil, errors.New("no host interface found")
return nil, errors.New("no host interface found: " + err.Error())
}
func cmdAdd(args *skel.CmdArgs) error {