Created
December 27, 2017 09:27
-
-
Save irake99/2062ea54bef89a072b67461cf955b079 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"flag" | |
"fmt" | |
"time" | |
"k8s.io/client-go/kubernetes" | |
"k8s.io/client-go/pkg/api/v1" | |
"k8s.io/client-go/pkg/fields" | |
"k8s.io/client-go/tools/cache" | |
"k8s.io/client-go/tools/clientcmd" | |
) | |
var ( | |
kubeconfig = flag.String("kubeconfig", "./config", "absolute path to the kubeconfig file") | |
) | |
func main() { | |
flag.Parse() | |
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig) | |
if err != nil { | |
panic(err.Error()) | |
} | |
clientset, err := kubernetes.NewForConfig(config) | |
if err != nil { | |
panic(err.Error()) | |
} | |
watchlist := cache.NewListWatchFromClient(clientset.Core().RESTClient(), "nodes", v1.NamespaceAll, | |
fields.ParseSelectorOrDie("metadata.name=node-1839f2")) | |
_, controller := cache.NewInformer( | |
watchlist, | |
&v1.Node{ | |
Status: v1.NodeStatus{ | |
Conditions: []v1.NodeCondition{ | |
{Type: v1.NodeReady, Status: v1.ConditionTrue}, | |
}, | |
}, | |
}, | |
time.Second*0, | |
cache.ResourceEventHandlerFuncs{ | |
AddFunc: func(obj interface{}) { | |
fmt.Printf("resource added: %s \n", obj) | |
}, | |
DeleteFunc: func(obj interface{}) { | |
fmt.Printf("resource deleted: %s \n", obj) | |
}, | |
UpdateFunc: func(oldObj, newObj interface{}) { | |
fmt.Printf("resource changed old: %s, new: %s \n", oldObj, newObj) | |
}, | |
}, | |
) | |
stop := make(chan struct{}) | |
go controller.Run(stop) | |
for { | |
time.Sleep(time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment