From 193b73292e32864286853efeccbc5190b5d3c84d Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Sat, 19 Oct 2019 10:44:25 +0100 Subject: [PATCH] Fix invoke for when no namespace is given Tested e2e with the operator on Kubernetes 1.14, also tested with the current version of faas-netes, which has the namespace endpoint. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- cmd/tester/main.go | 8 +++++--- types/function_list_builder.go | 18 +++++++++++++++--- types/topic_map.go | 4 +++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/cmd/tester/main.go b/cmd/tester/main.go index 9f008ab..dcbe355 100644 --- a/cmd/tester/main.go +++ b/cmd/tester/main.go @@ -15,10 +15,12 @@ import ( func main() { - var username, password string + var username, password, gateway string flag.StringVar(&username, "username", "admin", "username") flag.StringVar(&password, "password", "", "password") + flag.StringVar(&gateway, "gateway", "http://127.0.0.1:8080", "gateway") + flag.Parse() creds := &auth.BasicAuthCredentials{ @@ -28,7 +30,7 @@ func main() { config := &types.ControllerConfig{ RebuildInterval: time.Millisecond * 1000, - GatewayURL: "http://127.0.0.1:8080", + GatewayURL: gateway, PrintResponse: true, PrintResponseBody: true, } @@ -42,11 +44,11 @@ func main() { // Simulate events emitting from queue/pub-sub for { + log.Printf("Invoking on topic vm.powered.on - %s\n", gateway) time.Sleep(2 * time.Second) data := []byte("test " + time.Now().String()) controller.Invoke("vm.powered.on", &data) } - } // ResponseReceiver enables connector to receive results from the diff --git a/types/function_list_builder.go b/types/function_list_builder.go index 4fa547b..31bd066 100644 --- a/types/function_list_builder.go +++ b/types/function_list_builder.go @@ -113,15 +113,23 @@ func (s *FunctionLookupBuilder) Build() (map[string][]string, error) { if err != nil { return map[string][]string{}, err } - serviceMap := make(map[string][]string) - for _, namespace := range namespaces { + if len(namespaces) == 0 { + namespace := "" functions, err := s.getFunctions(namespace) if err != nil { return map[string][]string{}, err } serviceMap = buildServiceMap(&functions, s.TopicDelimiter, namespace, serviceMap) + } else { + for _, namespace := range namespaces { + functions, err := s.getFunctions(namespace) + if err != nil { + return map[string][]string{}, err + } + serviceMap = buildServiceMap(&functions, s.TopicDelimiter, namespace, serviceMap) + } } return serviceMap, err @@ -161,8 +169,12 @@ func appendServiceMap(key, function, namespace string, sm map[string][]string) m if sm[key] == nil { sm[key] = []string{} } + sep := "" + if len(namespace) > 0 { + sep = "." + } - functionPath := fmt.Sprintf("%s.%s", function, namespace) // add namespaces support + functionPath := fmt.Sprintf("%s%s%s", function, sep, namespace) sm[key] = append(sm[key], functionPath) } diff --git a/types/topic_map.go b/types/topic_map.go index bf56f0f..9042ea1 100644 --- a/types/topic_map.go +++ b/types/topic_map.go @@ -3,7 +3,9 @@ package types -import "sync" +import ( + "sync" +) func NewTopicMap() TopicMap { lookup := make(map[string][]string)