Fix router panic when trying to update route (#811)
This commit is contained in:
@@ -49,6 +49,7 @@ type HTTPTriggerSet struct {
|
||||
functions []crd.Function
|
||||
funcStore k8sCache.Store
|
||||
funcController k8sCache.Controller
|
||||
updateRouterRequestChannel chan struct{}
|
||||
|
||||
tsRoundTripperParams *tsRoundTripperParams
|
||||
}
|
||||
@@ -62,6 +63,7 @@ func makeHTTPTriggerSet(fmap *functionServiceMap, fissionClient *crd.FissionClie
|
||||
kubeClient: kubeClient,
|
||||
executor: executor,
|
||||
crdClient: crdClient,
|
||||
updateRouterRequestChannel: make(chan struct{}),
|
||||
tsRoundTripperParams: params,
|
||||
}
|
||||
var tStore, fnStore k8sCache.Store
|
||||
@@ -87,6 +89,7 @@ func (ts *HTTPTriggerSet) subscribeRouter(ctx context.Context, mr *mutableRouter
|
||||
log.Printf("Skipping continuous trigger updates")
|
||||
return
|
||||
}
|
||||
go ts.updateRouter()
|
||||
go ts.runWatcher(ctx, ts.funcController)
|
||||
go ts.runWatcher(ctx, ts.triggerController)
|
||||
}
|
||||
@@ -192,6 +195,11 @@ func (ts *HTTPTriggerSet) initTriggerController() (k8sCache.Store, k8sCache.Cont
|
||||
UpdateFunc: func(oldObj interface{}, newObj interface{}) {
|
||||
oldTrigger := oldObj.(*crd.HTTPTrigger)
|
||||
newTrigger := newObj.(*crd.HTTPTrigger)
|
||||
|
||||
if oldTrigger.Metadata.ResourceVersion == newTrigger.Metadata.ResourceVersion {
|
||||
return
|
||||
}
|
||||
|
||||
go updateIngress(oldTrigger, newTrigger, ts.kubeClient)
|
||||
ts.syncTriggers()
|
||||
},
|
||||
@@ -211,7 +219,13 @@ func (ts *HTTPTriggerSet) initFunctionController() (k8sCache.Store, k8sCache.Con
|
||||
ts.syncTriggers()
|
||||
},
|
||||
UpdateFunc: func(oldObj interface{}, newObj interface{}) {
|
||||
oldFn := oldObj.(*crd.Function)
|
||||
fn := newObj.(*crd.Function)
|
||||
|
||||
if oldFn.Metadata.ResourceVersion == fn.Metadata.ResourceVersion {
|
||||
return
|
||||
}
|
||||
|
||||
// update resolver function reference cache
|
||||
for key, rr := range ts.resolver.copy() {
|
||||
if key.functionReference.Name == fn.Metadata.Name &&
|
||||
@@ -236,6 +250,11 @@ func (ts *HTTPTriggerSet) runWatcher(ctx context.Context, controller k8sCache.Co
|
||||
}
|
||||
|
||||
func (ts *HTTPTriggerSet) syncTriggers() {
|
||||
ts.updateRouterRequestChannel <- struct{}{}
|
||||
}
|
||||
|
||||
func (ts *HTTPTriggerSet) updateRouter() {
|
||||
for range ts.updateRouterRequestChannel {
|
||||
// get triggers
|
||||
latestTriggers := ts.triggerStore.List()
|
||||
triggers := make([]crd.HTTPTrigger, len(latestTriggers))
|
||||
@@ -254,4 +273,5 @@ func (ts *HTTPTriggerSet) syncTriggers() {
|
||||
|
||||
// make a new router and use it
|
||||
ts.mutableRouter.updateRouter(ts.getRouter())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user