Skip to content

Instantly share code, notes, and snippets.

@khogeland
Last active September 10, 2019 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khogeland/302466c64410c0695493fa6c26d981fa to your computer and use it in GitHub Desktop.
Save khogeland/302466c64410c0695493fa6c26d981fa to your computer and use it in GitHub Desktop.
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