Created
October 21, 2019 05:41
-
-
Save jpeach/eb07e3fb7f896573244b6d9c00021838 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
diff --git cmd/contour/serve.go cmd/contour/serve.go | |
index c9e28b6..d43db72 100644 | |
--- cmd/contour/serve.go | |
+++ cmd/contour/serve.go | |
@@ -37,6 +37,7 @@ import ( | |
"gopkg.in/alecthomas/kingpin.v2" | |
"gopkg.in/yaml.v2" | |
coreinformers "k8s.io/client-go/informers" | |
+ "k8s.io/client-go/tools/cache" | |
"k8s.io/client-go/tools/leaderelection" | |
) | |
@@ -170,29 +171,37 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error { | |
} | |
// step 4. register our resource event handler with the k8s informers. | |
- coreInformers.Core().V1().Services().Informer().AddEventHandler(eh) | |
+ | |
+ informers := []cache.SharedIndexInformer{ | |
+ coreInformers.Core().V1().Services().Informer(), | |
+ contourInformers.Contour().V1beta1().IngressRoutes().Informer(), | |
+ contourInformers.Contour().V1beta1().TLSCertificateDelegations().Informer(), | |
+ contourInformers.Projectcontour().V1().HTTPProxies().Informer(), | |
+ contourInformers.Projectcontour().V1().TLSCertificateDelegations().Informer(), | |
+ } | |
// After K8s 1.13 the API server will automatically translate extensions/v1beta1.Ingress objects | |
// to networking/v1beta1.Ingress objects so we should only listen for one type or the other. | |
// The default behavior is to listen for networking/v1beta1.Ingress objects and let the API server | |
// transparently upgrade the extensions version for us. | |
if ctx.UseExtensionsV1beta1Ingress { | |
- coreInformers.Extensions().V1beta1().Ingresses().Informer().AddEventHandler(eh) | |
+ informers = append(informers, coreInformers.Extensions().V1beta1().Ingresses().Informer()) | |
} else { | |
- coreInformers.Networking().V1beta1().Ingresses().Informer().AddEventHandler(eh) | |
+ informers = append(informers, coreInformers.Networking().V1beta1().Ingresses().Informer()) | |
} | |
- contourInformers.Contour().V1beta1().IngressRoutes().Informer().AddEventHandler(eh) | |
- contourInformers.Contour().V1beta1().TLSCertificateDelegations().Informer().AddEventHandler(eh) | |
- contourInformers.Projectcontour().V1().HTTPProxies().Informer().AddEventHandler(eh) | |
- contourInformers.Projectcontour().V1().TLSCertificateDelegations().Informer().AddEventHandler(eh) | |
// Add informers for each root-ingressroute namespaces | |
for _, inf := range namespacedInformers { | |
- inf.Core().V1().Secrets().Informer().AddEventHandler(eh) | |
+ informers = append(informers, inf.Core().V1().Secrets().Informer()) | |
} | |
+ | |
// If root-ingressroutes are not defined, then add the informer for all namespaces | |
if len(namespacedInformers) == 0 { | |
- coreInformers.Core().V1().Secrets().Informer().AddEventHandler(eh) | |
+ informers = append(informers, coreInformers.Core().V1().Secrets().Informer()) | |
+ } | |
+ | |
+ for _, inf := range informers { | |
+ inf.AddEventHandler(eh) | |
} | |
// step 5. endpoints updates are handled directly by the EndpointsTranslator | |
@@ -200,7 +209,9 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error { | |
et := &contour.EndpointsTranslator{ | |
FieldLogger: log.WithField("context", "endpointstranslator"), | |
} | |
- coreInformers.Core().V1().Endpoints().Informer().AddEventHandler(et) | |
+ | |
+ informers = append(informers, coreInformers.Core().V1().Endpoints().Informer()) | |
+ informers[len(informers)-1].AddEventHandler(et) | |
// step 6. setup workgroup runner and register informers. | |
var g workgroup.Group | |
@@ -303,9 +314,18 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error { | |
eh.Metrics = metrics | |
eh.CacheHandler.Metrics = metrics | |
+ synced := make([]cache.InformerSynced, 0, len(informers)) | |
+ for _, inf := range informers { | |
+ synced = append(synced, inf.HasSynced) | |
+ } | |
+ | |
// step 13. create grpc handler and register with workgroup. | |
g.Add(func(stop <-chan struct{}) error { | |
log := log.WithField("context", "grpc") | |
+ | |
+ log.Printf("waiting for informer caches") | |
+ cache.WaitForCacheSync(stop, synced...) | |
+ | |
resources := map[string]cgrpc.Resource{ | |
eh.CacheHandler.ClusterCache.TypeURL(): &eh.CacheHandler.ClusterCache, | |
eh.CacheHandler.RouteCache.TypeURL(): &eh.CacheHandler.RouteCache, | |
@@ -361,12 +381,10 @@ type informer interface { | |
func startInformer(inf informer, log logrus.FieldLogger) func(stop <-chan struct{}) error { | |
return func(stop <-chan struct{}) error { | |
- log.Println("waiting for cache sync") | |
- inf.WaitForCacheSync(stop) | |
- | |
- log.Println("started") | |
- defer log.Println("stopped") | |
+ log.Println("starting informer") | |
inf.Start(stop) | |
+ | |
+ defer log.Println("stopped informer") | |
<-stop | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment