在main函数run后端之后,会创建协程调用WatchLeases,如下:
-
for循环中轮询,调用kube.go中对manager接口的实现,接口如下:
type kubeSubnetManager struct { annotations annotations client clientset.Interface nodeName string nodeStore listers.NodeLister nodeController cache.Controller subnetConf *subnet.Config events chan subnet.Event }
-
若events中存在事件,则返回LeaseWatchResult结构体,使用一个event初始化其Events成员,LeaseWatchResult结构体如下:
type LeaseWatchResult struct { // Either Events or Snapshot will be set. If Events is empty, it means // the cursor was out of range and Snapshot contains the current list // of items, even if empty. Events []Event `json:"events"` Snapshot []Lease `json:"snapshot"` Cursor interface{} `json:"cursor"` }
-
接着调用update,返回Event结构体变量
Event struct {
Type EventType `json:"type"`
Lease Lease `json:"lease,omitempty"`
}
- 将Event发送到管道中,此时就会触发管道另一端在等待的main中的Run,也就是vxlan接口中的实现的Run