本文整理汇总了Golang中github.com/coreos/flannel/subnet.WatchLeases函数的典型用法代码示例。如果您正苦于以下问题:Golang WatchLeases函数的具体用法?Golang WatchLeases怎么用?Golang WatchLeases使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WatchLeases函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Run
func (n *network) Run(ctx context.Context) {
wg := sync.WaitGroup{}
log.Info("Watching for new subnet leases")
evts := make(chan []subnet.Event)
wg.Add(1)
go func() {
subnet.WatchLeases(ctx, n.sm, n.name, n.lease, evts)
wg.Done()
}()
n.rl = make([]netlink.Route, 0, 10)
wg.Add(1)
go func() {
n.routeCheck(ctx)
wg.Done()
}()
defer wg.Wait()
for {
select {
case evtBatch := <-evts:
n.handleSubnetEvents(evtBatch)
case <-ctx.Done():
return
}
}
}
开发者ID:luxas,项目名称:flannel,代码行数:30,代码来源:network.go
示例2: Run
func (rb *HostgwBackend) Run() {
rb.wg.Add(1)
go func() {
subnet.LeaseRenewer(rb.ctx, rb.sm, rb.network, rb.lease)
rb.wg.Done()
}()
log.Info("Watching for new subnet leases")
evts := make(chan []subnet.Event)
rb.wg.Add(1)
go func() {
subnet.WatchLeases(rb.ctx, rb.sm, rb.network, rb.lease, evts)
rb.wg.Done()
}()
rb.rl = make([]netlink.Route, 0, 10)
rb.wg.Add(1)
go func() {
rb.routeCheck(rb.ctx)
rb.wg.Done()
}()
defer rb.wg.Wait()
for {
select {
case evtBatch := <-evts:
rb.handleSubnetEvents(evtBatch)
case <-rb.ctx.Done():
return
}
}
}
开发者ID:rajatchopra,项目名称:flannel,代码行数:34,代码来源:hostgw.go
示例3: Run
func (m *UdpBackend) Run(ctx context.Context) {
// one for each goroutine below
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
runCProxy(m.tun, m.conn, m.ctl2, m.tunNet.IP, m.mtu)
wg.Done()
}()
log.Info("Watching for new subnet leases")
evts := make(chan []subnet.Event)
wg.Add(1)
go func() {
subnet.WatchLeases(ctx, m.sm, m.network, m.lease, evts)
wg.Done()
}()
for {
select {
case evtBatch := <-evts:
m.processSubnetEvents(evtBatch)
case <-ctx.Done():
stopProxy(m.ctl)
break
}
}
wg.Wait()
}
开发者ID:OpenSorceress,项目名称:flannel,代码行数:33,代码来源:udp.go
示例4: Run
func (vb *VXLANBackend) Run() {
vb.wg.Add(1)
go func() {
subnet.LeaseRenewer(vb.ctx, vb.sm, vb.network, vb.lease)
log.Info("LeaseRenewer exited")
vb.wg.Done()
}()
log.Info("Watching for L3 misses")
misses := make(chan *netlink.Neigh, 100)
// Unfrtunately MonitorMisses does not take a cancel channel
// as there's no wait to interrupt netlink socket recv
go vb.dev.MonitorMisses(misses)
log.Info("Watching for new subnet leases")
evts := make(chan []subnet.Event)
vb.wg.Add(1)
go func() {
subnet.WatchLeases(vb.ctx, vb.sm, vb.network, vb.lease, evts)
log.Info("WatchLeases exited")
vb.wg.Done()
}()
defer vb.wg.Wait()
initialEvtsBatch := <-evts
for {
err := vb.handleInitialSubnetEvents(initialEvtsBatch)
if err == nil {
break
}
log.Error(err, " About to retry")
time.Sleep(time.Second)
}
for {
select {
case miss := <-misses:
vb.handleMiss(miss)
case evtBatch := <-evts:
vb.handleSubnetEvents(evtBatch)
case <-vb.ctx.Done():
return
}
}
}
开发者ID:rajatchopra,项目名称:flannel,代码行数:47,代码来源:vxlan.go
示例5: doTestWatch
func doTestWatch(t *testing.T, sm subnet.Manager) {
ctx, cancel := context.WithCancel(context.Background())
wg := sync.WaitGroup{}
wg.Add(1)
defer func() {
cancel()
wg.Wait()
}()
events := make(chan []subnet.Event)
go func() {
subnet.WatchLeases(ctx, sm, "_", nil, events)
wg.Done()
}()
// skip over the initial snapshot
<-events
attrs := &subnet.LeaseAttrs{
PublicIP: mustParseIP4("1.1.1.2"),
}
l, err := sm.AcquireLease(ctx, "_", attrs)
if err != nil {
t.Errorf("AcquireLease failed: %v", err)
return
}
if !mustParseIP4Net(expectedNetwork).Contains(l.Subnet.IP) {
t.Errorf("AcquireLease returned subnet not in network: %v (in %v)", l.Subnet, expectedNetwork)
}
evtBatch := <-events
if len(evtBatch) != 1 {
t.Fatalf("WatchSubnets produced wrong sized event batch")
}
evt := evtBatch[0]
if evt.Type != subnet.SubnetAdded {
t.Fatalf("WatchSubnets produced wrong event type")
}
if evt.Lease.Key() != l.Key() {
t.Errorf("WatchSubnet produced wrong subnet: expected %s, got %s", l.Key(), evt.Lease.Key())
}
}
开发者ID:nathanleiby,项目名称:flannel,代码行数:45,代码来源:remote_test.go
示例6: Run
func (n *network) Run(ctx context.Context) {
log.Info("Watching for L3 misses")
misses := make(chan *netlink.Neigh, 100)
// Unfrtunately MonitorMisses does not take a cancel channel
// as there's no wait to interrupt netlink socket recv
go n.dev.MonitorMisses(misses)
wg := sync.WaitGroup{}
log.Info("Watching for new subnet leases")
evts := make(chan []subnet.Event)
wg.Add(1)
go func() {
subnet.WatchLeases(ctx, n.sm, n.name, n.SubnetLease, evts)
log.Info("WatchLeases exited")
wg.Done()
}()
defer wg.Wait()
initialEvtsBatch := <-evts
for {
err := n.handleInitialSubnetEvents(initialEvtsBatch)
if err == nil {
break
}
log.Error(err, " About to retry")
time.Sleep(time.Second)
}
for {
select {
case miss := <-misses:
n.handleMiss(miss)
case evtBatch := <-evts:
n.handleSubnetEvents(evtBatch)
case <-ctx.Done():
return
}
}
}
开发者ID:vanloswang,项目名称:flannel,代码行数:42,代码来源:network.go
示例7: TestWatchLeases
func TestWatchLeases(t *testing.T) {
f := newFixture(t)
defer f.Close()
events := make(chan []subnet.Event)
f.wg.Add(1)
go func() {
subnet.WatchLeases(f.ctx, f.sm, "_", nil, events)
f.wg.Done()
}()
// skip over the initial snapshot
<-events
attrs := &subnet.LeaseAttrs{
PublicIP: mustParseIP4("1.1.1.2"),
}
l, err := f.sm.AcquireLease(f.ctx, "_", attrs)
if err != nil {
t.Errorf("AcquireLease failed: %v", err)
return
}
if !mustParseIP4Net(expectedNetwork).Contains(l.Subnet.IP) {
t.Errorf("AcquireLease returned subnet not in network: %v (in %v)", l.Subnet, expectedNetwork)
}
evtBatch := <-events
if len(evtBatch) != 1 {
t.Fatalf("WatchSubnets produced wrong sized event batch")
}
evt := evtBatch[0]
if evt.Type != subnet.EventAdded {
t.Fatalf("WatchSubnets produced wrong event type")
}
if evt.Lease.Key() != l.Key() {
t.Errorf("WatchSubnet produced wrong subnet: expected %s, got %s", l.Key(), evt.Lease.Key())
}
}
开发者ID:erickcantwell,项目名称:flannel,代码行数:41,代码来源:remote_test.go
示例8: monitorEvents
func (m *UdpBackend) monitorEvents() {
log.Info("Watching for new subnet leases")
evts := make(chan []subnet.Event)
m.wg.Add(1)
go func() {
subnet.WatchLeases(m.ctx, m.sm, m.network, m.lease, evts)
m.wg.Done()
}()
for {
select {
case evtBatch := <-evts:
m.processSubnetEvents(evtBatch)
case <-m.ctx.Done():
return
}
}
}
开发者ID:rajatchopra,项目名称:flannel,代码行数:21,代码来源:udp.go
示例9: Run
func (n *network) Run(ctx context.Context) {
defer func() {
n.tun.Close()
n.conn.Close()
n.ctl.Close()
n.ctl2.Close()
}()
// one for each goroutine below
wg := sync.WaitGroup{}
defer wg.Wait()
wg.Add(1)
go func() {
runCProxy(n.tun, n.conn, n.ctl2, n.tunNet.IP, n.MTU())
wg.Done()
}()
log.Info("Watching for new subnet leases")
evts := make(chan []subnet.Event)
wg.Add(1)
go func() {
subnet.WatchLeases(ctx, n.sm, n.name, n.SubnetLease, evts)
wg.Done()
}()
for {
select {
case evtBatch := <-evts:
n.processSubnetEvents(evtBatch)
case <-ctx.Done():
stopProxy(n.ctl)
return
}
}
}
开发者ID:smessmer,项目名称:flannel,代码行数:39,代码来源:network.go
注:本文中的github.com/coreos/flannel/subnet.WatchLeases函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论