Skip to content

Commit

Permalink
Fix invoke for when no namespace is given
Browse files Browse the repository at this point in the history
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) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Oct 19, 2019
1 parent 480d121 commit 193b732
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 5 additions & 3 deletions cmd/tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
}
Expand All @@ -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
Expand Down
18 changes: 15 additions & 3 deletions types/function_list_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 3 additions & 1 deletion types/topic_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

package types

import "sync"
import (
"sync"
)

func NewTopicMap() TopicMap {
lookup := make(map[string][]string)
Expand Down

0 comments on commit 193b732

Please sign in to comment.