Use k8s client store to sync functions and triggers for fast synchronization (#382)
This commit is contained in:
committed by
Soam Vasani
parent
5f14b9b0ae
commit
380b7d1bcd
+16
-15
@@ -41,7 +41,9 @@ type HTTPTriggerSet struct {
|
|||||||
poolmgr *poolmgrClient.Client
|
poolmgr *poolmgrClient.Client
|
||||||
resolver *functionReferenceResolver
|
resolver *functionReferenceResolver
|
||||||
triggers []crd.HTTPTrigger
|
triggers []crd.HTTPTrigger
|
||||||
|
triggerStore k8sCache.Store
|
||||||
functions []crd.Function
|
functions []crd.Function
|
||||||
|
funcStore k8sCache.Store
|
||||||
crdClient *rest.RESTClient
|
crdClient *rest.RESTClient
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,9 +141,6 @@ func (ts *HTTPTriggerSet) updateTriggerStatusFailed(ht *crd.HTTPTrigger, err err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ts *HTTPTriggerSet) watchTriggers() {
|
func (ts *HTTPTriggerSet) watchTriggers() {
|
||||||
// sync all http triggers
|
|
||||||
ts.syncTriggers()
|
|
||||||
|
|
||||||
watchlist := k8sCache.NewListWatchFromClient(ts.crdClient, "httptriggers", metav1.NamespaceDefault, fields.Everything())
|
watchlist := k8sCache.NewListWatchFromClient(ts.crdClient, "httptriggers", metav1.NamespaceDefault, fields.Everything())
|
||||||
listWatch := &k8sCache.ListWatch{
|
listWatch := &k8sCache.ListWatch{
|
||||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||||
@@ -152,7 +151,7 @@ func (ts *HTTPTriggerSet) watchTriggers() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
resyncPeriod := 30 * time.Second
|
resyncPeriod := 30 * time.Second
|
||||||
_, controller := k8sCache.NewInformer(listWatch, &crd.HTTPTrigger{}, resyncPeriod,
|
store, controller := k8sCache.NewInformer(listWatch, &crd.HTTPTrigger{}, resyncPeriod,
|
||||||
k8sCache.ResourceEventHandlerFuncs{
|
k8sCache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(obj interface{}) {
|
AddFunc: func(obj interface{}) {
|
||||||
ts.syncTriggers()
|
ts.syncTriggers()
|
||||||
@@ -164,6 +163,7 @@ func (ts *HTTPTriggerSet) watchTriggers() {
|
|||||||
ts.syncTriggers()
|
ts.syncTriggers()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
ts.triggerStore = store
|
||||||
stop := make(chan struct{})
|
stop := make(chan struct{})
|
||||||
defer func() {
|
defer func() {
|
||||||
stop <- struct{}{}
|
stop <- struct{}{}
|
||||||
@@ -172,8 +172,6 @@ func (ts *HTTPTriggerSet) watchTriggers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ts *HTTPTriggerSet) watchFunctions() {
|
func (ts *HTTPTriggerSet) watchFunctions() {
|
||||||
ts.syncTriggers()
|
|
||||||
|
|
||||||
watchlist := k8sCache.NewListWatchFromClient(ts.crdClient, "functions", metav1.NamespaceDefault, fields.Everything())
|
watchlist := k8sCache.NewListWatchFromClient(ts.crdClient, "functions", metav1.NamespaceDefault, fields.Everything())
|
||||||
listWatch := &k8sCache.ListWatch{
|
listWatch := &k8sCache.ListWatch{
|
||||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||||
@@ -184,7 +182,7 @@ func (ts *HTTPTriggerSet) watchFunctions() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
resyncPeriod := 30 * time.Second
|
resyncPeriod := 30 * time.Second
|
||||||
_, controller := k8sCache.NewInformer(listWatch, &crd.Function{}, resyncPeriod,
|
store, controller := k8sCache.NewInformer(listWatch, &crd.Function{}, resyncPeriod,
|
||||||
k8sCache.ResourceEventHandlerFuncs{
|
k8sCache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(obj interface{}) {
|
AddFunc: func(obj interface{}) {
|
||||||
ts.syncTriggers()
|
ts.syncTriggers()
|
||||||
@@ -208,6 +206,7 @@ func (ts *HTTPTriggerSet) watchFunctions() {
|
|||||||
ts.syncTriggers()
|
ts.syncTriggers()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
ts.funcStore = store
|
||||||
stop := make(chan struct{})
|
stop := make(chan struct{})
|
||||||
defer func() {
|
defer func() {
|
||||||
stop <- struct{}{}
|
stop <- struct{}{}
|
||||||
@@ -219,18 +218,20 @@ func (ts *HTTPTriggerSet) syncTriggers() {
|
|||||||
log.Printf("Syncing http triggers")
|
log.Printf("Syncing http triggers")
|
||||||
|
|
||||||
// get triggers
|
// get triggers
|
||||||
triggers, err := ts.fissionClient.HTTPTriggers(metav1.NamespaceAll).List(metav1.ListOptions{})
|
latestTriggers := ts.triggerStore.List()
|
||||||
if err != nil {
|
triggers := make([]crd.HTTPTrigger, len(latestTriggers))
|
||||||
log.Fatalf("Failed to get http trigger list: %v", err)
|
for _, t := range latestTriggers {
|
||||||
|
triggers = append(triggers, *t.(*crd.HTTPTrigger))
|
||||||
}
|
}
|
||||||
ts.triggers = triggers.Items
|
ts.triggers = triggers
|
||||||
|
|
||||||
// get functions
|
// get functions
|
||||||
functions, err := ts.fissionClient.Functions(metav1.NamespaceAll).List(metav1.ListOptions{})
|
latestFunctions := ts.funcStore.List()
|
||||||
if err != nil {
|
functions := make([]crd.Function, len(latestFunctions))
|
||||||
log.Fatalf("Failed to get function list: %v", err)
|
for _, f := range latestFunctions {
|
||||||
|
functions = append(functions, *f.(*crd.Function))
|
||||||
}
|
}
|
||||||
ts.functions = functions.Items
|
ts.functions = functions
|
||||||
|
|
||||||
// make a new router and use it
|
// make a new router and use it
|
||||||
ts.mutableRouter.updateRouter(ts.getRouter())
|
ts.mutableRouter.updateRouter(ts.getRouter())
|
||||||
|
|||||||
Reference in New Issue
Block a user