Last active
September 10, 2019 01:18
-
-
Save khogeland/302466c64410c0695493fa6c26d981fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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/informers" | |
"k8s.io/client-go/kubernetes" | |
"k8s.io/client-go/tools/cache" | |
"k8s.io/client-go/tools/clientcmd" | |
) | |
var ( | |
kubeConfig = flag.String("kubeConfig", "", "path to kubeconfig") | |
) | |
func main() { | |
flag.Parse() | |
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfig) | |
if err != nil { | |
panic(err) | |
} | |
kubeClient, err := kubernetes.NewForConfig(config) | |
if err != nil { | |
panic(err) | |
} | |
stopCh := make(chan struct{}, 1) | |
go func() { | |
time.Sleep(5 * time.Second) | |
stopCh <- struct{}{} | |
}() | |
coreV1InformerFactory := informers.NewSharedInformerFactoryWithOptions(kubeClient, time.Duration(30)*time.Second) | |
go coreV1InformerFactory.Start(stopCh) | |
time.Sleep(1 * time.Second) | |
informer := coreV1InformerFactory.Core().V1().ResourceQuotas() | |
informer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{}) | |
fmt.Println("waiting for cache sync") | |
if !cache.WaitForCacheSync(stopCh, informer.Informer().HasSynced) { | |
panic("timed out") | |
} | |
fmt.Println("not dead!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment