func NodeListWatch() {
fmt.Printf("Start Node List Watch...\n")
restClient := K8sClientSet.CoreV1().RESTClient()
watchlist := cache.NewListWatchFromClient(restClient, "nodes", k8smetav1.NamespaceAll, fields.Everything())
_, controller := cache.NewInformer(
watchlist,
&k8sv1.Node{},
time.Second*0,
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
if nodeobj, ok := obj.(*k8sv1.Node); ok {
NodeChange("add", nodeobj)
} else {
fmt.Printf("obj is not Node\n")
fmt.Println(reflect.TypeOf(obj))
}
},
DeleteFunc: func(obj interface{}) {
if nodeobj, ok := obj.(*k8sv1.Node); ok {
NodeChange("delete", nodeobj)
} else {
fmt.Printf("obj is not Node\n")
fmt.Println(reflect.TypeOf(obj))
}
},
UpdateFunc: func(oldObj, newObj interface{}) {
if nodeobj, ok := newObj.(*k8sv1.Node); ok {
NodeChange("change", nodeobj)
} else {
fmt.Printf("newObj is not Node\n")
fmt.Println(reflect.TypeOf(newObj))
}
},
},
)
stop := make(chan struct{})
defer close(stop)
go controller.Run(stop)
for {
time.Sleep(time.Second * 5)
}
}
k8s Informer(node)
最新推荐文章于 2023-04-26 13:29:21 发布