Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
Update to return empty set for Namespaces call
Browse files Browse the repository at this point in the history
The namespace call added to OpenFaaS was not implemented in
here, and that meant that calling it returned an empty response
rather than some valid json, A user noted that this caused an error
in the connector-sdk, which has had a fix added, but we need this
namespace endpoint to not return none (well it was actually erroring)

Signed-off-by: Alistair Hey <[email protected]>
  • Loading branch information
Waterdrips authored and alexellis committed Dec 17, 2019
1 parent 47988f8 commit ecf4229
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions handlers/namespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package handlers

import (
"encoding/json"
"log"
"net/http"
)

// Swarm does not use namespaces, so we return an empty list. see https://github.com/openfaas-incubator/connector-sdk/pull/46
func NamespaceLister() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
namespaces := []string{}
nsJSON, err := json.Marshal(namespaces)

if err != nil {
log.Printf("Unable to marshal namespaces into JSON %q", err)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte("\"error\": \"unable to return namespaces\""))
}

w.WriteHeader(http.StatusOK)
w.Write(nsJSON)
}
}

2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func main() {
InfoHandler: handlers.MakeInfoHandler(version.BuildVersion(), version.GitCommit),
SecretHandler: handlers.MakeSecretsHandler(dockerClient),
LogHandler: logs.NewLogHandlerFunc(handlers.NewLogRequester(dockerClient), cfg.FaaSConfig.WriteTimeout),
ListNamespaceHandler: handlers.NamespaceLister(),

}

bootstrapConfig := bootTypes.FaaSConfig{
Expand Down

0 comments on commit ecf4229

Please sign in to comment.