VMware vSphere Integrated Containers provider (#206)
* 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
This commit is contained in:
132
vendor/github.com/docker/libnetwork/driverapi/driverapi.go
generated
vendored
Normal file
132
vendor/github.com/docker/libnetwork/driverapi/driverapi.go
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
package driverapi
|
||||
|
||||
import "net"
|
||||
|
||||
// NetworkPluginEndpointType represents the Endpoint Type used by Plugin system
|
||||
const NetworkPluginEndpointType = "NetworkDriver"
|
||||
|
||||
// Driver is an interface that every plugin driver needs to implement.
|
||||
type Driver interface {
|
||||
// CreateNetwork invokes the driver method to create a network passing
|
||||
// the network id and network specific config. The config mechanism will
|
||||
// eventually be replaced with labels which are yet to be introduced.
|
||||
CreateNetwork(nid string, options map[string]interface{}, ipV4Data, ipV6Data []IPAMData) error
|
||||
|
||||
// DeleteNetwork invokes the driver method to delete network passing
|
||||
// the network id.
|
||||
DeleteNetwork(nid string) error
|
||||
|
||||
// CreateEndpoint invokes the driver method to create an endpoint
|
||||
// passing the network id, endpoint id endpoint information and driver
|
||||
// specific config. The endpoint information can be either consumed by
|
||||
// the driver or populated by the driver. The config mechanism will
|
||||
// eventually be replaced with labels which are yet to be introduced.
|
||||
CreateEndpoint(nid, eid string, ifInfo InterfaceInfo, options map[string]interface{}) error
|
||||
|
||||
// DeleteEndpoint invokes the driver method to delete an endpoint
|
||||
// passing the network id and endpoint id.
|
||||
DeleteEndpoint(nid, eid string) error
|
||||
|
||||
// EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint
|
||||
EndpointOperInfo(nid, eid string) (map[string]interface{}, error)
|
||||
|
||||
// Join method is invoked when a Sandbox is attached to an endpoint.
|
||||
Join(nid, eid string, sboxKey string, jinfo JoinInfo, options map[string]interface{}) error
|
||||
|
||||
// Leave method is invoked when a Sandbox detaches from an endpoint.
|
||||
Leave(nid, eid string) error
|
||||
|
||||
// DiscoverNew is a notification for a new discovery event, Example:a new node joining a cluster
|
||||
DiscoverNew(dType DiscoveryType, data interface{}) error
|
||||
|
||||
// DiscoverDelete is a notification for a discovery delete event, Example:a node leaving a cluster
|
||||
DiscoverDelete(dType DiscoveryType, data interface{}) error
|
||||
|
||||
// Type returns the the type of this driver, the network type this driver manages
|
||||
Type() string
|
||||
}
|
||||
|
||||
// InterfaceInfo provides a go interface for drivers to retrive
|
||||
// network information to interface resources.
|
||||
type InterfaceInfo interface {
|
||||
// SetMacAddress allows the driver to set the mac address to the endpoint interface
|
||||
// during the call to CreateEndpoint, if the mac address is not already set.
|
||||
SetMacAddress(mac net.HardwareAddr) error
|
||||
|
||||
// SetIPAddress allows the driver to set the ip address to the endpoint interface
|
||||
// during the call to CreateEndpoint, if the address is not already set.
|
||||
// The API is to be used to assign both the IPv4 and IPv6 address types.
|
||||
SetIPAddress(ip *net.IPNet) error
|
||||
|
||||
// MacAddress returns the MAC address.
|
||||
MacAddress() net.HardwareAddr
|
||||
|
||||
// Address returns the IPv4 address.
|
||||
Address() *net.IPNet
|
||||
|
||||
// AddressIPv6 returns the IPv6 address.
|
||||
AddressIPv6() *net.IPNet
|
||||
}
|
||||
|
||||
// InterfaceNameInfo provides a go interface for the drivers to assign names
|
||||
// to interfaces.
|
||||
type InterfaceNameInfo interface {
|
||||
// SetNames method assigns the srcName and dstPrefix for the interface.
|
||||
SetNames(srcName, dstPrefix string) error
|
||||
}
|
||||
|
||||
// JoinInfo represents a set of resources that the driver has the ability to provide during
|
||||
// join time.
|
||||
type JoinInfo interface {
|
||||
// InterfaceName returns a InterfaceNameInfo go interface to facilitate
|
||||
// setting the names for the interface.
|
||||
InterfaceName() InterfaceNameInfo
|
||||
|
||||
// SetGateway sets the default IPv4 gateway when a container joins the endpoint.
|
||||
SetGateway(net.IP) error
|
||||
|
||||
// SetGatewayIPv6 sets the default IPv6 gateway when a container joins the endpoint.
|
||||
SetGatewayIPv6(net.IP) error
|
||||
|
||||
// AddStaticRoute adds a routes to the sandbox.
|
||||
// It may be used in addtion to or instead of a default gateway (as above).
|
||||
AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error
|
||||
|
||||
// DisableGatewayService tells libnetwork not to provide Default GW for the container
|
||||
DisableGatewayService()
|
||||
}
|
||||
|
||||
// DriverCallback provides a Callback interface for Drivers into LibNetwork
|
||||
type DriverCallback interface {
|
||||
// RegisterDriver provides a way for Remote drivers to dynamically register new NetworkType and associate with a driver instance
|
||||
RegisterDriver(name string, driver Driver, capability Capability) error
|
||||
}
|
||||
|
||||
// Capability represents the high level capabilities of the drivers which libnetwork can make use of
|
||||
type Capability struct {
|
||||
DataScope string
|
||||
}
|
||||
|
||||
// DiscoveryType represents the type of discovery element the DiscoverNew function is invoked on
|
||||
type DiscoveryType int
|
||||
|
||||
const (
|
||||
// NodeDiscovery represents Node join/leave events provided by discovery
|
||||
NodeDiscovery = iota + 1
|
||||
)
|
||||
|
||||
// NodeDiscoveryData represents the structure backing the node discovery data json string
|
||||
type NodeDiscoveryData struct {
|
||||
Address string
|
||||
Self bool
|
||||
}
|
||||
|
||||
// IPAMData represents the per-network ip related
|
||||
// operational information libnetwork will send
|
||||
// to the network driver during CreateNetwork()
|
||||
type IPAMData struct {
|
||||
AddressSpace string
|
||||
Pool *net.IPNet
|
||||
Gateway *net.IPNet
|
||||
AuxAddresses map[string]*net.IPNet
|
||||
}
|
||||
119
vendor/github.com/docker/libnetwork/driverapi/driverapi_test.go
generated
vendored
Normal file
119
vendor/github.com/docker/libnetwork/driverapi/driverapi_test.go
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
package driverapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
_ "github.com/docker/libnetwork/testutils"
|
||||
"github.com/docker/libnetwork/types"
|
||||
)
|
||||
|
||||
func TestIPDataMarshalling(t *testing.T) {
|
||||
i := &IPAMData{
|
||||
AddressSpace: "giallo",
|
||||
Pool: &net.IPNet{IP: net.IP{10, 10, 10, 8}, Mask: net.IPMask{255, 255, 255, 0}},
|
||||
Gateway: &net.IPNet{IP: net.IP{10, 10, 10, 254}, Mask: net.IPMask{255, 255, 255, 0}},
|
||||
AuxAddresses: map[string]*net.IPNet{
|
||||
"ip1": &net.IPNet{IP: net.IP{10, 10, 10, 1}, Mask: net.IPMask{255, 255, 255, 0}},
|
||||
"ip2": &net.IPNet{IP: net.IP{10, 10, 10, 2}, Mask: net.IPMask{255, 255, 255, 0}},
|
||||
},
|
||||
}
|
||||
|
||||
b, err := json.Marshal(i)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ii := &IPAMData{}
|
||||
err = json.Unmarshal(b, &ii)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if i.AddressSpace != ii.AddressSpace || !types.CompareIPNet(i.Pool, ii.Pool) ||
|
||||
!types.CompareIPNet(i.Gateway, ii.Gateway) ||
|
||||
!compareAddresses(i.AuxAddresses, ii.AuxAddresses) {
|
||||
t.Fatalf("JSON marsh/unmarsh failed.\nOriginal:\n%s\nDecoded:\n%s", i, ii)
|
||||
}
|
||||
}
|
||||
|
||||
func compareAddresses(a, b map[string]*net.IPNet) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
if len(a) > 0 {
|
||||
for k := range a {
|
||||
if !types.CompareIPNet(a[k], b[k]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func TestValidateAndIsV6(t *testing.T) {
|
||||
var err error
|
||||
|
||||
i := &IPAMData{
|
||||
Pool: &net.IPNet{IP: net.IP{10, 10, 10, 8}, Mask: net.IPMask{255, 255, 255, 0}},
|
||||
Gateway: &net.IPNet{IP: net.IP{10, 10, 10, 254}, Mask: net.IPMask{255, 255, 255, 0}},
|
||||
AuxAddresses: map[string]*net.IPNet{
|
||||
"ip1": &net.IPNet{IP: net.IP{10, 10, 10, 1}, Mask: net.IPMask{255, 255, 255, 0}},
|
||||
"ip2": &net.IPNet{IP: net.IP{10, 10, 10, 2}, Mask: net.IPMask{255, 255, 255, 0}},
|
||||
},
|
||||
}
|
||||
|
||||
// Check ip version
|
||||
if i.IsV6() {
|
||||
t.Fatalf("incorrect ip version returned")
|
||||
}
|
||||
orig := i.Pool
|
||||
if i.Pool, err = types.ParseCIDR("2003::33/64"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !i.IsV6() {
|
||||
t.Fatalf("incorrect ip version returned")
|
||||
}
|
||||
i.Pool = orig
|
||||
|
||||
// valid ip data
|
||||
if err = i.Validate(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// incongruent gw ver
|
||||
if i.Gateway, err = types.ParseCIDR("2001::45/65"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = i.Validate(); err == nil {
|
||||
t.Fatalf("expected error but succeded")
|
||||
}
|
||||
i.Gateway = nil
|
||||
|
||||
// incongruent secondary ip ver
|
||||
if i.AuxAddresses["ip2"], err = types.ParseCIDR("2002::44/80"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = i.Validate(); err == nil {
|
||||
t.Fatalf("expected error but succeded")
|
||||
}
|
||||
delete(i.AuxAddresses, "ip2")
|
||||
|
||||
// gw outside pool
|
||||
if i.Gateway, err = types.ParseCIDR("10.10.15.254/24"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = i.Validate(); err == nil {
|
||||
t.Fatalf("expected error but succeded")
|
||||
}
|
||||
i.Gateway = nil
|
||||
|
||||
// sec ip outside of pool
|
||||
if i.AuxAddresses["ip1"], err = types.ParseCIDR("10.10.2.1/24"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = i.Validate(); err == nil {
|
||||
t.Fatalf("expected error but succeded")
|
||||
}
|
||||
}
|
||||
56
vendor/github.com/docker/libnetwork/driverapi/errors.go
generated
vendored
Normal file
56
vendor/github.com/docker/libnetwork/driverapi/errors.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
package driverapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ErrNoNetwork is returned if no network with the specified id exists
|
||||
type ErrNoNetwork string
|
||||
|
||||
func (enn ErrNoNetwork) Error() string {
|
||||
return fmt.Sprintf("No network (%s) exists", string(enn))
|
||||
}
|
||||
|
||||
// NotFound denotes the type of this error
|
||||
func (enn ErrNoNetwork) NotFound() {}
|
||||
|
||||
// ErrEndpointExists is returned if more than one endpoint is added to the network
|
||||
type ErrEndpointExists string
|
||||
|
||||
func (ee ErrEndpointExists) Error() string {
|
||||
return fmt.Sprintf("Endpoint (%s) already exists (Only one endpoint allowed)", string(ee))
|
||||
}
|
||||
|
||||
// Forbidden denotes the type of this error
|
||||
func (ee ErrEndpointExists) Forbidden() {}
|
||||
|
||||
// ErrNotImplemented is returned when a Driver has not implemented an API yet
|
||||
type ErrNotImplemented struct{}
|
||||
|
||||
func (eni *ErrNotImplemented) Error() string {
|
||||
return "The API is not implemented yet"
|
||||
}
|
||||
|
||||
// NotImplemented denotes the type of this error
|
||||
func (eni *ErrNotImplemented) NotImplemented() {}
|
||||
|
||||
// ErrNoEndpoint is returned if no endpoint with the specified id exists
|
||||
type ErrNoEndpoint string
|
||||
|
||||
func (ene ErrNoEndpoint) Error() string {
|
||||
return fmt.Sprintf("No endpoint (%s) exists", string(ene))
|
||||
}
|
||||
|
||||
// NotFound denotes the type of this error
|
||||
func (ene ErrNoEndpoint) NotFound() {}
|
||||
|
||||
// ErrActiveRegistration represents an error when a driver is registered to a networkType that is previously registered
|
||||
type ErrActiveRegistration string
|
||||
|
||||
// Error interface for ErrActiveRegistration
|
||||
func (ar ErrActiveRegistration) Error() string {
|
||||
return fmt.Sprintf("Driver already registered for type %q", string(ar))
|
||||
}
|
||||
|
||||
// Forbidden denotes the type of this error
|
||||
func (ar ErrActiveRegistration) Forbidden() {}
|
||||
103
vendor/github.com/docker/libnetwork/driverapi/ipamdata.go
generated
vendored
Normal file
103
vendor/github.com/docker/libnetwork/driverapi/ipamdata.go
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
package driverapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/docker/libnetwork/types"
|
||||
)
|
||||
|
||||
// MarshalJSON encodes IPAMData into json message
|
||||
func (i *IPAMData) MarshalJSON() ([]byte, error) {
|
||||
m := map[string]interface{}{}
|
||||
m["AddressSpace"] = i.AddressSpace
|
||||
if i.Pool != nil {
|
||||
m["Pool"] = i.Pool.String()
|
||||
}
|
||||
if i.Gateway != nil {
|
||||
m["Gateway"] = i.Gateway.String()
|
||||
}
|
||||
if i.AuxAddresses != nil {
|
||||
am := make(map[string]string, len(i.AuxAddresses))
|
||||
for k, v := range i.AuxAddresses {
|
||||
am[k] = v.String()
|
||||
}
|
||||
m["AuxAddresses"] = am
|
||||
}
|
||||
return json.Marshal(m)
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes a json message into IPAMData
|
||||
func (i *IPAMData) UnmarshalJSON(data []byte) error {
|
||||
var (
|
||||
m map[string]interface{}
|
||||
err error
|
||||
)
|
||||
if err := json.Unmarshal(data, &m); err != nil {
|
||||
return err
|
||||
}
|
||||
i.AddressSpace = m["AddressSpace"].(string)
|
||||
if v, ok := m["Pool"]; ok {
|
||||
if i.Pool, err = types.ParseCIDR(v.(string)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if v, ok := m["Gateway"]; ok {
|
||||
if i.Gateway, err = types.ParseCIDR(v.(string)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if v, ok := m["AuxAddresses"]; ok {
|
||||
b, _ := json.Marshal(v)
|
||||
var am map[string]string
|
||||
if err = json.Unmarshal(b, &am); err != nil {
|
||||
return err
|
||||
}
|
||||
i.AuxAddresses = make(map[string]*net.IPNet, len(am))
|
||||
for k, v := range am {
|
||||
if i.AuxAddresses[k], err = types.ParseCIDR(v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate checks wheter the IPAMData structure contains congruent data
|
||||
func (i *IPAMData) Validate() error {
|
||||
var isV6 bool
|
||||
if i.Pool == nil {
|
||||
return types.BadRequestErrorf("invalid pool")
|
||||
}
|
||||
if i.Gateway == nil {
|
||||
return types.BadRequestErrorf("invalid gateway address")
|
||||
}
|
||||
isV6 = i.IsV6()
|
||||
if isV6 && i.Gateway.IP.To4() != nil || !isV6 && i.Gateway.IP.To4() == nil {
|
||||
return types.BadRequestErrorf("incongruent ip versions for pool and gateway")
|
||||
}
|
||||
for k, sip := range i.AuxAddresses {
|
||||
if isV6 && sip.IP.To4() != nil || !isV6 && sip.IP.To4() == nil {
|
||||
return types.BadRequestErrorf("incongruent ip versions for pool and secondary ip address %s", k)
|
||||
}
|
||||
}
|
||||
if !i.Pool.Contains(i.Gateway.IP) {
|
||||
return types.BadRequestErrorf("invalid gateway address (%s) does not belong to the pool (%s)", i.Gateway, i.Pool)
|
||||
}
|
||||
for k, sip := range i.AuxAddresses {
|
||||
if !i.Pool.Contains(sip.IP) {
|
||||
return types.BadRequestErrorf("invalid secondary address %s (%s) does not belong to the pool (%s)", k, i.Gateway, i.Pool)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsV6 returns wheter this is an IPv6 IPAMData structure
|
||||
func (i *IPAMData) IsV6() bool {
|
||||
return nil == i.Pool.IP.To4()
|
||||
}
|
||||
|
||||
func (i *IPAMData) String() string {
|
||||
return fmt.Sprintf("AddressSpace: %s\nPool: %v\nGateway: %v\nAddresses: %v", i.AddressSpace, i.Pool, i.Gateway, i.AuxAddresses)
|
||||
}
|
||||
Reference in New Issue
Block a user