mirror of
https://github.com/openfaas/faas.git
synced 2025-06-21 14:23:25 +00:00
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:
committed by
Alex Ellis
parent
238ce1be23
commit
df4126d8f5
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user