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:
121
vendor/github.com/docker/libnetwork/hostdiscovery/hostdiscovery.go
generated
vendored
Normal file
121
vendor/github.com/docker/libnetwork/hostdiscovery/hostdiscovery.go
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
package hostdiscovery
|
||||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
||||
mapset "github.com/deckarep/golang-set"
|
||||
"github.com/docker/docker/pkg/discovery"
|
||||
// Including KV
|
||||
_ "github.com/docker/docker/pkg/discovery/kv"
|
||||
"github.com/docker/libkv/store/consul"
|
||||
"github.com/docker/libkv/store/etcd"
|
||||
"github.com/docker/libkv/store/zookeeper"
|
||||
"github.com/docker/libnetwork/types"
|
||||
)
|
||||
|
||||
type hostDiscovery struct {
|
||||
watcher discovery.Watcher
|
||||
nodes mapset.Set
|
||||
stopChan chan struct{}
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
func init() {
|
||||
consul.Register()
|
||||
etcd.Register()
|
||||
zookeeper.Register()
|
||||
}
|
||||
|
||||
// NewHostDiscovery function creates a host discovery object
|
||||
func NewHostDiscovery(watcher discovery.Watcher) HostDiscovery {
|
||||
return &hostDiscovery{watcher: watcher, nodes: mapset.NewSet(), stopChan: make(chan struct{})}
|
||||
}
|
||||
|
||||
func (h *hostDiscovery) Watch(activeCallback ActiveCallback, joinCallback JoinCallback, leaveCallback LeaveCallback) error {
|
||||
h.Lock()
|
||||
d := h.watcher
|
||||
h.Unlock()
|
||||
if d == nil {
|
||||
return types.BadRequestErrorf("invalid discovery watcher")
|
||||
}
|
||||
discoveryCh, errCh := d.Watch(h.stopChan)
|
||||
go h.monitorDiscovery(discoveryCh, errCh, activeCallback, joinCallback, leaveCallback)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *hostDiscovery) monitorDiscovery(ch <-chan discovery.Entries, errCh <-chan error,
|
||||
activeCallback ActiveCallback, joinCallback JoinCallback, leaveCallback LeaveCallback) {
|
||||
for {
|
||||
select {
|
||||
case entries := <-ch:
|
||||
h.processCallback(entries, activeCallback, joinCallback, leaveCallback)
|
||||
case err := <-errCh:
|
||||
if err != nil {
|
||||
log.Errorf("discovery error: %v", err)
|
||||
}
|
||||
case <-h.stopChan:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *hostDiscovery) StopDiscovery() error {
|
||||
h.Lock()
|
||||
stopChan := h.stopChan
|
||||
h.watcher = nil
|
||||
h.Unlock()
|
||||
|
||||
close(stopChan)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *hostDiscovery) processCallback(entries discovery.Entries,
|
||||
activeCallback ActiveCallback, joinCallback JoinCallback, leaveCallback LeaveCallback) {
|
||||
updated := hosts(entries)
|
||||
h.Lock()
|
||||
existing := h.nodes
|
||||
added, removed := diff(existing, updated)
|
||||
h.nodes = updated
|
||||
h.Unlock()
|
||||
|
||||
activeCallback()
|
||||
if len(added) > 0 {
|
||||
joinCallback(added)
|
||||
}
|
||||
if len(removed) > 0 {
|
||||
leaveCallback(removed)
|
||||
}
|
||||
}
|
||||
|
||||
func diff(existing mapset.Set, updated mapset.Set) (added []net.IP, removed []net.IP) {
|
||||
addSlice := updated.Difference(existing).ToSlice()
|
||||
removeSlice := existing.Difference(updated).ToSlice()
|
||||
for _, ip := range addSlice {
|
||||
added = append(added, net.ParseIP(ip.(string)))
|
||||
}
|
||||
for _, ip := range removeSlice {
|
||||
removed = append(removed, net.ParseIP(ip.(string)))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (h *hostDiscovery) Fetch() []net.IP {
|
||||
h.Lock()
|
||||
defer h.Unlock()
|
||||
ips := []net.IP{}
|
||||
for _, ipstr := range h.nodes.ToSlice() {
|
||||
ips = append(ips, net.ParseIP(ipstr.(string)))
|
||||
}
|
||||
return ips
|
||||
}
|
||||
|
||||
func hosts(entries discovery.Entries) mapset.Set {
|
||||
hosts := mapset.NewSet()
|
||||
for _, entry := range entries {
|
||||
hosts.Add(entry.Host)
|
||||
}
|
||||
return hosts
|
||||
}
|
||||
22
vendor/github.com/docker/libnetwork/hostdiscovery/hostdiscovery_api.go
generated
vendored
Normal file
22
vendor/github.com/docker/libnetwork/hostdiscovery/hostdiscovery_api.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
package hostdiscovery
|
||||
|
||||
import "net"
|
||||
|
||||
// JoinCallback provides a callback event for new node joining the cluster
|
||||
type JoinCallback func(entries []net.IP)
|
||||
|
||||
// ActiveCallback provides a callback event for active discovery event
|
||||
type ActiveCallback func()
|
||||
|
||||
// LeaveCallback provides a callback event for node leaving the cluster
|
||||
type LeaveCallback func(entries []net.IP)
|
||||
|
||||
// HostDiscovery primary interface
|
||||
type HostDiscovery interface {
|
||||
//Watch Node join and leave cluster events
|
||||
Watch(activeCallback ActiveCallback, joinCallback JoinCallback, leaveCallback LeaveCallback) error
|
||||
// StopDiscovery stops the discovery perocess
|
||||
StopDiscovery() error
|
||||
// Fetch returns a list of host IPs that are currently discovered
|
||||
Fetch() []net.IP
|
||||
}
|
||||
77
vendor/github.com/docker/libnetwork/hostdiscovery/hostdiscovery_test.go
generated
vendored
Normal file
77
vendor/github.com/docker/libnetwork/hostdiscovery/hostdiscovery_test.go
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
package hostdiscovery
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
mapset "github.com/deckarep/golang-set"
|
||||
_ "github.com/docker/libnetwork/testutils"
|
||||
|
||||
"github.com/docker/docker/pkg/discovery"
|
||||
)
|
||||
|
||||
func TestDiff(t *testing.T) {
|
||||
existing := mapset.NewSetFromSlice([]interface{}{"1.1.1.1", "2.2.2.2"})
|
||||
addedIP := "3.3.3.3"
|
||||
updated := existing.Clone()
|
||||
updated.Add(addedIP)
|
||||
|
||||
added, removed := diff(existing, updated)
|
||||
if len(added) != 1 {
|
||||
t.Fatalf("Diff failed for an Add update. Expecting 1 element, but got %d elements", len(added))
|
||||
}
|
||||
if added[0].String() != addedIP {
|
||||
t.Fatalf("Expecting : %v, Got : %v", addedIP, added[0])
|
||||
}
|
||||
if len(removed) > 0 {
|
||||
t.Fatalf("Diff failed for remove use-case. Expecting 0 element, but got %d elements", len(removed))
|
||||
}
|
||||
|
||||
updated = mapset.NewSetFromSlice([]interface{}{addedIP})
|
||||
added, removed = diff(existing, updated)
|
||||
if len(removed) != 2 {
|
||||
t.Fatalf("Diff failed for an remove update. Expecting 2 element, but got %d elements", len(removed))
|
||||
}
|
||||
if len(added) != 1 {
|
||||
t.Fatalf("Diff failed for add use-case. Expecting 1 element, but got %d elements", len(added))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddedCallback(t *testing.T) {
|
||||
hd := hostDiscovery{}
|
||||
hd.nodes = mapset.NewSetFromSlice([]interface{}{"1.1.1.1"})
|
||||
update := []*discovery.Entry{&discovery.Entry{Host: "1.1.1.1", Port: "0"}, &discovery.Entry{Host: "2.2.2.2", Port: "0"}}
|
||||
|
||||
added := false
|
||||
removed := false
|
||||
hd.processCallback(update, func() {}, func(hosts []net.IP) { added = true }, func(hosts []net.IP) { removed = true })
|
||||
if !added {
|
||||
t.Fatalf("Expecting a Added callback notification. But none received")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemovedCallback(t *testing.T) {
|
||||
hd := hostDiscovery{}
|
||||
hd.nodes = mapset.NewSetFromSlice([]interface{}{"1.1.1.1", "2.2.2.2"})
|
||||
update := []*discovery.Entry{&discovery.Entry{Host: "1.1.1.1", Port: "0"}}
|
||||
|
||||
added := false
|
||||
removed := false
|
||||
hd.processCallback(update, func() {}, func(hosts []net.IP) { added = true }, func(hosts []net.IP) { removed = true })
|
||||
if !removed {
|
||||
t.Fatalf("Expecting a Removed callback notification. But none received")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoCallback(t *testing.T) {
|
||||
hd := hostDiscovery{}
|
||||
hd.nodes = mapset.NewSetFromSlice([]interface{}{"1.1.1.1", "2.2.2.2"})
|
||||
update := []*discovery.Entry{&discovery.Entry{Host: "1.1.1.1", Port: "0"}, &discovery.Entry{Host: "2.2.2.2", Port: "0"}}
|
||||
|
||||
added := false
|
||||
removed := false
|
||||
hd.processCallback(update, func() {}, func(hosts []net.IP) { added = true }, func(hosts []net.IP) { removed = true })
|
||||
if added || removed {
|
||||
t.Fatalf("Not expecting any callback notification. But received a callback")
|
||||
}
|
||||
}
|
||||
6
vendor/github.com/docker/libnetwork/hostdiscovery/libnetwork.toml
generated
vendored
Normal file
6
vendor/github.com/docker/libnetwork/hostdiscovery/libnetwork.toml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
title = "LibNetwork Configuration file"
|
||||
|
||||
[cluster]
|
||||
discovery = "consul://localhost:8500"
|
||||
Address = "6.5.5.5"
|
||||
Heartbeat = 3
|
||||
Reference in New Issue
Block a user