Skip to content

Instantly share code, notes, and snippets.

@alekc
Created May 25, 2020 07:45
Show Gist options
  • Save alekc/fe698eac7c37168ce7b441f5ecf6d188 to your computer and use it in GitHub Desktop.
Save alekc/fe698eac7c37168ce7b441f5ecf6d188 to your computer and use it in GitHub Desktop.
Watcher snippet for k8
var stopCh <- chan struct{}
watcher := cache.NewListWatchFromClient(k8Client.RESTClient(),"nodes", metaV1.NamespaceAll,fields.Everything())
_, controller := cache.NewInformer(
watcher,
&coreV1.Node{},
time.Second * 10,
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
node, ok := obj.(*coreV1.Node)
if !ok {
log.Fatal().
Str("object_type",fmt.Sprintf("%T",node)).
Msg("list/watch returned non-node object")
}
log.Info().Str("node_name",node.Name)
//annotations := node.GetAnnotations()
//if val,ok := annotations["flannel.alpha.coreos.com/public-ip-overwrite"]; ok {
//
//}
time.Sleep(time.Second * 5)
log.Printf("handling node %s", node.GetName())
},
},
)
controller.Run(stopCh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment