k8s informer

// https://www.cnblogs.com/yangyuliufeng/p/13611126.html

stopCH := make(chan struct{})
defer close(stopCH)
sharedInformers := informers.NewSharedInformerFactory(clientset, time.Minute)  
informer := sharedInformers.Core().V1().Pods().Informer()    
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{     //为Pod资源添加资源事件回调方法
   AddFunc: func(obj interface{}){
      mObj := obj.(v1.Object)
      log.Print("创建新Pod:",mObj.GetName())
   },
   UpdateFunc: func(oldObj, newObj interface{}){
      oObj := oldObj.(v1.Object)
      nObj := newObj.(v1.Object)
      log.Print(oObj.GetName(),",",nObj.GetName())
   },
   DeleteFunc: func(obj interface{}) {
      mObj :=obj.(v1.Object)
      log.Print("删除旧Pod:",mObj.GetName())
   },
})
informer.Run(stopCH)

k8s informer

上一篇:Javascript中setTimeout和setInterval的区别和使用


下一篇:P6327 区间加区间sin和