Created
May 25, 2020 07:45
-
-
Save alekc/fe698eac7c37168ce7b441f5ecf6d188 to your computer and use it in GitHub Desktop.
Watcher snippet for k8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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