Scale functions with namespace option

Allows alerts to trigger functions to scale when they
also have an optional namespace set.

Tested e2e with Kubernetes 1.15 and a non-default namespace.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2019-09-20 15:54:12 +01:00
committed by Alex Ellis
parent 238ce1be23
commit df4126d8f5
11 changed files with 148 additions and 62 deletions

View File

@ -29,22 +29,22 @@ type FunctionCache struct {
}
// Set replica count for functionName
func (fc *FunctionCache) Set(functionName string, serviceQueryResponse ServiceQueryResponse) {
func (fc *FunctionCache) Set(functionName, namespace string, serviceQueryResponse ServiceQueryResponse) {
fc.Sync.Lock()
defer fc.Sync.Unlock()
if _, exists := fc.Cache[functionName]; !exists {
fc.Cache[functionName] = &FunctionMeta{}
if _, exists := fc.Cache[functionName+"."+namespace]; !exists {
fc.Cache[functionName+"."+namespace] = &FunctionMeta{}
}
fc.Cache[functionName].LastRefresh = time.Now()
fc.Cache[functionName].ServiceQueryResponse = serviceQueryResponse
fc.Cache[functionName+"."+namespace].LastRefresh = time.Now()
fc.Cache[functionName+"."+namespace].ServiceQueryResponse = serviceQueryResponse
// entry.LastRefresh = time.Now()
// entry.ServiceQueryResponse = serviceQueryResponse
}
// Get replica count for functionName
func (fc *FunctionCache) Get(functionName string) (ServiceQueryResponse, bool) {
func (fc *FunctionCache) Get(functionName, namespace string) (ServiceQueryResponse, bool) {
replicas := ServiceQueryResponse{
AvailableReplicas: 0,
}
@ -53,7 +53,7 @@ func (fc *FunctionCache) Get(functionName string) (ServiceQueryResponse, bool) {
fc.Sync.RLock()
defer fc.Sync.RUnlock()
if val, exists := fc.Cache[functionName]; exists {
if val, exists := fc.Cache[functionName+"."+namespace]; exists {
replicas = val.ServiceQueryResponse
hit = !val.Expired(fc.Expiry)
}