* Add Virtual Kubelet provider for VIC Initial virtual kubelet provider for VMware VIC. This provider currently handles creating and starting of a pod VM via the VIC portlayer and persona server. Image store handling via the VIC persona server. This provider currently requires the feature/wolfpack branch of VIC. * Added pod stop and delete. Also added node capacity. Added the ability to stop and delete pod VMs via VIC. Also retrieve node capacity information from the VCH. * Cleanup and readme file Some file clean up and added a Readme.md markdown file for the VIC provider. * Cleaned up errors, added function comments, moved operation code 1. Cleaned up error handling. Set standard for creating errors. 2. Added method prototype comments for all interface functions. 3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder. * Add mocking code and unit tests for podcache, podcreator, and podstarter Used the unit test framework used in VIC to handle assertions in the provider's unit test. Mocking code generated using OSS project mockery, which is compatible with the testify assertion framework. * Vendored packages for the VIC provider Requires feature/wolfpack branch of VIC and a few specific commit sha of projects used within VIC. * Implementation of POD Stopper and Deleter unit tests (#4) * Updated files for initial PR
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package bridge
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
|
|
"github.com/vishvananda/netlink"
|
|
)
|
|
|
|
const (
|
|
// DefaultBridgeName is the default name for the bridge interface managed
|
|
// by the driver when unspecified by the caller.
|
|
DefaultBridgeName = "docker0"
|
|
)
|
|
|
|
// Interface models the bridge network device.
|
|
type bridgeInterface struct {
|
|
Link netlink.Link
|
|
bridgeIPv4 *net.IPNet
|
|
bridgeIPv6 *net.IPNet
|
|
gatewayIPv4 net.IP
|
|
gatewayIPv6 net.IP
|
|
}
|
|
|
|
// newInterface creates a new bridge interface structure. It attempts to find
|
|
// an already existing device identified by the configuration BridgeName field,
|
|
// or the default bridge name when unspecified), but doesn't attempt to create
|
|
// one when missing
|
|
func newInterface(config *networkConfiguration) *bridgeInterface {
|
|
i := &bridgeInterface{}
|
|
|
|
// Initialize the bridge name to the default if unspecified.
|
|
if config.BridgeName == "" {
|
|
config.BridgeName = DefaultBridgeName
|
|
}
|
|
|
|
// Attempt to find an existing bridge named with the specified name.
|
|
i.Link, _ = netlink.LinkByName(config.BridgeName)
|
|
return i
|
|
}
|
|
|
|
// exists indicates if the existing bridge interface exists on the system.
|
|
func (i *bridgeInterface) exists() bool {
|
|
return i.Link != nil
|
|
}
|
|
|
|
// addresses returns a single IPv4 address and all IPv6 addresses for the
|
|
// bridge interface.
|
|
func (i *bridgeInterface) addresses() (netlink.Addr, []netlink.Addr, error) {
|
|
v4addr, err := netlink.AddrList(i.Link, netlink.FAMILY_V4)
|
|
if err != nil {
|
|
return netlink.Addr{}, nil, err
|
|
}
|
|
|
|
v6addr, err := netlink.AddrList(i.Link, netlink.FAMILY_V6)
|
|
if err != nil {
|
|
return netlink.Addr{}, nil, err
|
|
}
|
|
|
|
if len(v4addr) == 0 {
|
|
return netlink.Addr{}, v6addr, nil
|
|
}
|
|
return v4addr[0], v6addr, nil
|
|
}
|
|
|
|
func (i *bridgeInterface) programIPv6Address() error {
|
|
_, nlAddressList, err := i.addresses()
|
|
if err != nil {
|
|
return &IPv6AddrAddError{IP: i.bridgeIPv6, Err: fmt.Errorf("failed to retrieve address list: %v", err)}
|
|
}
|
|
nlAddr := netlink.Addr{IPNet: i.bridgeIPv6}
|
|
if findIPv6Address(nlAddr, nlAddressList) {
|
|
return nil
|
|
}
|
|
if err := netlink.AddrAdd(i.Link, &nlAddr); err != nil {
|
|
return &IPv6AddrAddError{IP: i.bridgeIPv6, Err: err}
|
|
}
|
|
return nil
|
|
}
|