Add db infra to IPAM
This commit is contained in:
1 parent
38c6eb28e8
commit
ad036499eb
3 files changed
+13
-5
No files matched your search
+4
-1
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/weaveworks/mesh"
|
"github.com/weaveworks/mesh"
|
||||||
|
|
||||||
"github.com/weaveworks/weave/common"
|
"github.com/weaveworks/weave/common"
|
||||||
|
"github.com/weaveworks/weave/db"
|
||||||
"github.com/weaveworks/weave/ipam/paxos"
|
"github.com/weaveworks/weave/ipam/paxos"
|
||||||
"github.com/weaveworks/weave/ipam/ring"
|
"github.com/weaveworks/weave/ipam/ring"
|
||||||
"github.com/weaveworks/weave/ipam/space"
|
"github.com/weaveworks/weave/ipam/space"
|
||||||
@@ -54,6 +55,7 @@ type Allocator struct {
|
|||||||
pendingAllocates []operation // held until we get some free space
|
pendingAllocates []operation // held until we get some free space
|
||||||
pendingClaims []operation // held until we know who owns the space
|
pendingClaims []operation // held until we know who owns the space
|
||||||
dead map[string]time.Time // containers we heard were dead, and when
|
dead map[string]time.Time // containers we heard were dead, and when
|
||||||
|
db db.DB // persistence
|
||||||
gossip mesh.Gossip // our link to the outside world for sending messages
|
gossip mesh.Gossip // our link to the outside world for sending messages
|
||||||
paxos *paxos.Node
|
paxos *paxos.Node
|
||||||
paxosActive bool
|
paxosActive bool
|
||||||
@@ -64,12 +66,13 @@ type Allocator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewAllocator creates and initialises a new Allocator
|
// NewAllocator creates and initialises a new Allocator
|
||||||
func NewAllocator(ourName mesh.PeerName, ourUID mesh.PeerUID, ourNickname string, universe address.Range, quorum uint, isKnownPeer func(name mesh.PeerName) bool) *Allocator {
|
func NewAllocator(ourName mesh.PeerName, ourUID mesh.PeerUID, ourNickname string, universe address.Range, quorum uint, db db.DB, isKnownPeer func(name mesh.PeerName) bool) *Allocator {
|
||||||
return &Allocator{
|
return &Allocator{
|
||||||
ourName: ourName,
|
ourName: ourName,
|
||||||
universe: universe,
|
universe: universe,
|
||||||
ring: ring.New(universe.Start, universe.End, ourName),
|
ring: ring.New(universe.Start, universe.End, ourName),
|
||||||
owned: make(map[string][]address.Address),
|
owned: make(map[string][]address.Address),
|
||||||
|
db: db,
|
||||||
paxos: paxos.NewNode(ourName, ourUID, quorum),
|
paxos: paxos.NewNode(ourName, ourUID, quorum),
|
||||||
nicknames: map[mesh.PeerName]string{ourName: ourNickname},
|
nicknames: map[mesh.PeerName]string{ourName: ourNickname},
|
||||||
isKnownPeer: isKnownPeer,
|
isKnownPeer: isKnownPeer,
|
||||||
|
|||||||
@@ -123,6 +123,11 @@ func CheckAllExpectedMessagesSent(allocs ...*Allocator) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type mockDB struct{}
|
||||||
|
|
||||||
|
func (d *mockDB) Load(_ string, _ interface{}) error { return nil }
|
||||||
|
func (d *mockDB) Save(_ string, _ interface{}) error { return nil }
|
||||||
|
|
||||||
func makeAllocator(name string, cidrStr string, quorum uint) (*Allocator, address.Range) {
|
func makeAllocator(name string, cidrStr string, quorum uint) (*Allocator, address.Range) {
|
||||||
peername, err := mesh.PeerNameFromString(name)
|
peername, err := mesh.PeerNameFromString(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -135,7 +140,7 @@ func makeAllocator(name string, cidrStr string, quorum uint) (*Allocator, addres
|
|||||||
}
|
}
|
||||||
|
|
||||||
alloc := NewAllocator(peername, mesh.PeerUID(rand.Int63()),
|
alloc := NewAllocator(peername, mesh.PeerUID(rand.Int63()),
|
||||||
"nick-"+name, cidr.Range(), quorum, func(mesh.PeerName) bool { return true })
|
"nick-"+name, cidr.Range(), quorum, new(mockDB), func(mesh.PeerName) bool { return true })
|
||||||
|
|
||||||
return alloc, cidr.HostRange()
|
return alloc, cidr.HostRange()
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -195,7 +195,7 @@ func main() {
|
|||||||
defaultSubnet address.CIDR
|
defaultSubnet address.CIDR
|
||||||
)
|
)
|
||||||
if iprangeCIDR != "" {
|
if iprangeCIDR != "" {
|
||||||
allocator, defaultSubnet = createAllocator(router.Router, iprangeCIDR, ipsubnetCIDR, determineQuorum(peerCount, peers), isKnownPeer)
|
allocator, defaultSubnet = createAllocator(router.Router, iprangeCIDR, ipsubnetCIDR, determineQuorum(peerCount, peers), db, isKnownPeer)
|
||||||
observeContainers(allocator)
|
observeContainers(allocator)
|
||||||
} else if peerCount > 0 {
|
} else if peerCount > 0 {
|
||||||
Log.Fatal("--init-peer-count flag specified without --ipalloc-range")
|
Log.Fatal("--init-peer-count flag specified without --ipalloc-range")
|
||||||
@@ -315,7 +315,7 @@ func parseAndCheckCIDR(cidrStr string) address.CIDR {
|
|||||||
return cidr
|
return cidr
|
||||||
}
|
}
|
||||||
|
|
||||||
func createAllocator(router *mesh.Router, ipRangeStr string, defaultSubnetStr string, quorum uint, isKnownPeer func(mesh.PeerName) bool) (*ipam.Allocator, address.CIDR) {
|
func createAllocator(router *mesh.Router, ipRangeStr string, defaultSubnetStr string, quorum uint, db db.DB, isKnownPeer func(mesh.PeerName) bool) (*ipam.Allocator, address.CIDR) {
|
||||||
ipRange := parseAndCheckCIDR(ipRangeStr)
|
ipRange := parseAndCheckCIDR(ipRangeStr)
|
||||||
defaultSubnet := ipRange
|
defaultSubnet := ipRange
|
||||||
if defaultSubnetStr != "" {
|
if defaultSubnetStr != "" {
|
||||||
@@ -324,7 +324,7 @@ func createAllocator(router *mesh.Router, ipRangeStr string, defaultSubnetStr st
|
|||||||
Log.Fatalf("IP address allocation default subnet %s does not overlap with allocation range %s", defaultSubnet, ipRange)
|
Log.Fatalf("IP address allocation default subnet %s does not overlap with allocation range %s", defaultSubnet, ipRange)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
allocator := ipam.NewAllocator(router.Ourself.Peer.Name, router.Ourself.Peer.UID, router.Ourself.Peer.NickName, ipRange.Range(), quorum, isKnownPeer)
|
allocator := ipam.NewAllocator(router.Ourself.Peer.Name, router.Ourself.Peer.UID, router.Ourself.Peer.NickName, ipRange.Range(), quorum, db, isKnownPeer)
|
||||||
|
|
||||||
allocator.SetInterfaces(router.NewGossip("IPallocation", allocator))
|
allocator.SetInterfaces(router.NewGossip("IPallocation", allocator))
|
||||||
allocator.Start()
|
allocator.Start()
|
||||||
|
|||||||
Reference in new issue
Block a user