Use common controller/store for httpTriggerSet and functionReferenceResolver (#390)

This fixes a bug where functionReferenceResolver returned out-of-date function metadata and caused the router to proxy requests to old function pods.

It also uses the go context package to shutdown the controller when the router is shutting down.
This commit is contained in:
Ta-Ching Chen
2017-11-09 07:07:14 -08:00
committed by Soam Vasani
parent 9694ba4fd1
commit da07b35a96
4 changed files with 58 additions and 81 deletions
+3 -19
View File
@@ -36,8 +36,6 @@ type (
// functionReferenceResolver provides a resolver to turn a function
// reference into a resolveResult
functionReferenceResolver struct {
fissionClient *crd.FissionClient
// FunctionReference -> function metadata
refCache *cache.Cache
@@ -68,28 +66,14 @@ const (
resolveResultSingleFunction = iota
)
func makeFunctionReferenceResolver(fissionClient *crd.FissionClient) *functionReferenceResolver {
func makeFunctionReferenceResolver(store k8sCache.Store) *functionReferenceResolver {
frr := &functionReferenceResolver{
fissionClient: fissionClient,
refCache: cache.MakeCache(time.Minute, 0),
refCache: cache.MakeCache(time.Minute, 0),
store: store,
}
return frr
}
// Sync starts syncing crd function resources from k8s api server
func (frr *functionReferenceResolver) Sync(crdClient *rest.RESTClient) {
stopCh := make(chan struct{})
store, controller := makeK8SCache(crdClient)
frr.stopCh = stopCh
frr.store = store
go controller.Run(stopCh)
}
// Stop stops crd resources syncing
func (frr *functionReferenceResolver) Stop() {
frr.stopCh <- struct{}{}
}
func makeK8SCache(crdClient *rest.RESTClient) (k8sCache.Store, k8sCache.Controller) {
watchlist := k8sCache.NewListWatchFromClient(crdClient, "functions", metav1.NamespaceDefault, fields.Everything())
listWatch := &k8sCache.ListWatch{