* 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
150 lines
3.7 KiB
Go
150 lines
3.7 KiB
Go
package overlay
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
"github.com/docker/libnetwork/driverapi"
|
|
"github.com/docker/libnetwork/types"
|
|
"github.com/vishvananda/netlink"
|
|
)
|
|
|
|
// Join method is invoked when a Sandbox is attached to an endpoint.
|
|
func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) error {
|
|
if err := validateID(nid, eid); err != nil {
|
|
return err
|
|
}
|
|
|
|
n := d.network(nid)
|
|
if n == nil {
|
|
return fmt.Errorf("could not find network with id %s", nid)
|
|
}
|
|
|
|
ep := n.endpoint(eid)
|
|
if ep == nil {
|
|
return fmt.Errorf("could not find endpoint with id %s", eid)
|
|
}
|
|
|
|
s := n.getSubnetforIP(ep.addr)
|
|
if s == nil {
|
|
return fmt.Errorf("could not find subnet for endpoint %s", eid)
|
|
}
|
|
|
|
if err := n.obtainVxlanID(s); err != nil {
|
|
return fmt.Errorf("couldn't get vxlan id for %q: %v", s.subnetIP.String(), err)
|
|
}
|
|
|
|
if err := n.joinSandbox(); err != nil {
|
|
return fmt.Errorf("network sandbox join failed: %v", err)
|
|
}
|
|
|
|
if err := n.joinSubnetSandbox(s); err != nil {
|
|
return fmt.Errorf("subnet sandbox join failed for %q: %v", s.subnetIP.String(), err)
|
|
}
|
|
|
|
// joinSubnetSandbox gets called when an endpoint comes up on a new subnet in the
|
|
// overlay network. Hence the Endpoint count should be updated outside joinSubnetSandbox
|
|
n.incEndpointCount()
|
|
|
|
sbox := n.sandbox()
|
|
|
|
name1, name2, err := createVethPair()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ep.ifName = name2
|
|
|
|
// Set the container interface and its peer MTU to 1450 to allow
|
|
// for 50 bytes vxlan encap (inner eth header(14) + outer IP(20) +
|
|
// outer UDP(8) + vxlan header(8))
|
|
veth, err := netlink.LinkByName(name1)
|
|
if err != nil {
|
|
return fmt.Errorf("cound not find link by name %s: %v", name1, err)
|
|
}
|
|
err = netlink.LinkSetMTU(veth, vxlanVethMTU)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := sbox.AddInterface(name1, "veth",
|
|
sbox.InterfaceOptions().Master(s.brName)); err != nil {
|
|
return fmt.Errorf("could not add veth pair inside the network sandbox: %v", err)
|
|
}
|
|
|
|
veth, err = netlink.LinkByName(name2)
|
|
if err != nil {
|
|
return fmt.Errorf("could not find link by name %s: %v", name2, err)
|
|
}
|
|
err = netlink.LinkSetMTU(veth, vxlanVethMTU)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := netlink.LinkSetHardwareAddr(veth, ep.mac); err != nil {
|
|
return fmt.Errorf("could not set mac address (%v) to the container interface: %v", ep.mac, err)
|
|
}
|
|
|
|
for _, sub := range n.subnets {
|
|
if sub == s {
|
|
continue
|
|
}
|
|
if err := jinfo.AddStaticRoute(sub.subnetIP, types.NEXTHOP, s.gwIP.IP); err != nil {
|
|
log.Errorf("Adding subnet %s static route in network %q failed\n", s.subnetIP, n.id)
|
|
}
|
|
}
|
|
|
|
if iNames := jinfo.InterfaceName(); iNames != nil {
|
|
err = iNames.SetNames(name2, "eth")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
d.peerDbAdd(nid, eid, ep.addr.IP, ep.addr.Mask, ep.mac,
|
|
net.ParseIP(d.bindAddress), true)
|
|
d.pushLocalEndpointEvent("join", nid, eid)
|
|
|
|
return nil
|
|
}
|
|
|
|
// Leave method is invoked when a Sandbox detaches from an endpoint.
|
|
func (d *driver) Leave(nid, eid string) error {
|
|
if err := validateID(nid, eid); err != nil {
|
|
return err
|
|
}
|
|
|
|
n := d.network(nid)
|
|
if n == nil {
|
|
return fmt.Errorf("could not find network with id %s", nid)
|
|
}
|
|
|
|
ep := n.endpoint(eid)
|
|
|
|
if ep == nil {
|
|
return types.InternalMaskableErrorf("could not find endpoint with id %s", eid)
|
|
}
|
|
|
|
if d.notifyCh != nil {
|
|
d.notifyCh <- ovNotify{
|
|
action: "leave",
|
|
nid: nid,
|
|
eid: eid,
|
|
}
|
|
}
|
|
|
|
n.leaveSandbox()
|
|
|
|
link, err := netlink.LinkByName(ep.ifName)
|
|
if err != nil {
|
|
log.Warnf("Failed to retrieve interface link for interface removal on endpoint leave: %v", err)
|
|
return nil
|
|
}
|
|
if err := netlink.LinkDel(link); err != nil {
|
|
log.Warnf("Failed to delete interface link on endpoint leave: %v", err)
|
|
}
|
|
|
|
return nil
|
|
}
|