Add namespaces endpoint

This is being added because multiple namespaces can now be used
on Kubernetes. By listing namespaces, a client such as the UI
or CLI can then enumerate the namespaces to find functions
which may span across more than one namespace.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd) 2019-09-21 17:59:12 +01:00 committed by Alex Ellis
parent 0488e510ee
commit 137b63e61f
5 changed files with 30 additions and 17 deletions

6
gateway/Gopkg.lock generated
View File

@ -93,15 +93,15 @@
version = "v1.0.0" version = "v1.0.0"
[[projects]] [[projects]]
digest = "1:9e4fe15cd865c2200690de4722f7115eb85ae5fdb22b8215d54d890563e92536" digest = "1:5e3d58f3f10333495afd0248507ef369bfc4a938ff679d568f7ac38af1e067dd"
name = "github.com/openfaas/faas-provider" name = "github.com/openfaas/faas-provider"
packages = [ packages = [
"auth", "auth",
"types", "types",
] ]
pruneopts = "UT" pruneopts = "UT"
revision = "ba3fa3b0ae00f0b9222851f3e03b2e6ea8672998" revision = "eafd85a3b360d8e0982c3a1db43e6d5fee9b85e2"
version = "0.10.1" version = "0.10.2"
[[projects]] [[projects]]
digest = "1:f7b0087a32b4f017ce89562494ae510f21e7d22e70cc1911640a32ebe583e92e" digest = "1:f7b0087a32b4f017ce89562494ae510f21e7d22e70cc1911640a32ebe583e92e"

View File

@ -6,7 +6,7 @@ ignored = ["github.com/openfaas/faas/gateway/queue"]
[[constraint]] [[constraint]]
name = "github.com/openfaas/faas-provider" name = "github.com/openfaas/faas-provider"
version = "0.10.1" version = "0.10.2"
[[constraint]] [[constraint]]
name = "github.com/gorilla/mux" name = "github.com/gorilla/mux"

View File

@ -114,9 +114,12 @@ func main() {
faasHandlers.DeleteFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector) faasHandlers.DeleteFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector)
faasHandlers.UpdateFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector) faasHandlers.UpdateFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector)
faasHandlers.QueryFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector) faasHandlers.QueryFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector)
faasHandlers.InfoHandler = handlers.MakeInfoHandler(handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector)) faasHandlers.InfoHandler = handlers.MakeInfoHandler(handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector))
faasHandlers.SecretHandler = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector) faasHandlers.SecretHandler = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector)
faasHandlers.NamespaceListerHandler = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer, serviceAuthInjector)
externalServiceQuery := plugin.NewExternalServiceQuery(*config.FunctionsProviderURL, serviceAuthInjector) externalServiceQuery := plugin.NewExternalServiceQuery(*config.FunctionsProviderURL, serviceAuthInjector)
faasHandlers.Alert = handlers.MakeNotifierWrapper( faasHandlers.Alert = handlers.MakeNotifierWrapper(
handlers.MakeAlertHandler(externalServiceQuery, config.Namespace), handlers.MakeAlertHandler(externalServiceQuery, config.Namespace),
@ -177,6 +180,8 @@ func main() {
decorateExternalAuth(faasHandlers.SecretHandler, config.UpstreamTimeout, config.AuthProxyURL, config.AuthProxyPassBody) decorateExternalAuth(faasHandlers.SecretHandler, config.UpstreamTimeout, config.AuthProxyURL, config.AuthProxyPassBody)
faasHandlers.LogProxyHandler = faasHandlers.LogProxyHandler =
decorateExternalAuth(faasHandlers.LogProxyHandler, config.UpstreamTimeout, config.AuthProxyURL, config.AuthProxyPassBody) decorateExternalAuth(faasHandlers.LogProxyHandler, config.UpstreamTimeout, config.AuthProxyURL, config.AuthProxyPassBody)
faasHandlers.NamespaceListerHandler =
decorateExternalAuth(faasHandlers.NamespaceListerHandler, config.UpstreamTimeout, config.AuthProxyURL, config.AuthProxyPassBody)
} }
r := mux.NewRouter() r := mux.NewRouter()
@ -213,6 +218,8 @@ func main() {
r.HandleFunc("/system/secrets", faasHandlers.SecretHandler).Methods(http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete) r.HandleFunc("/system/secrets", faasHandlers.SecretHandler).Methods(http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete)
r.HandleFunc("/system/logs", faasHandlers.LogProxyHandler).Methods(http.MethodGet) r.HandleFunc("/system/logs", faasHandlers.LogProxyHandler).Methods(http.MethodGet)
r.HandleFunc("/system/namespaces", faasHandlers.NamespaceListerHandler).Methods(http.MethodGet)
if faasHandlers.QueuedProxy != nil { if faasHandlers.QueuedProxy != nil {
r.HandleFunc("/async-function/{name:["+NameExpression+"]+}/", faasHandlers.QueuedProxy).Methods(http.MethodPost) r.HandleFunc("/async-function/{name:["+NameExpression+"]+}/", faasHandlers.QueuedProxy).Methods(http.MethodPost)
r.HandleFunc("/async-function/{name:["+NameExpression+"]+}", faasHandlers.QueuedProxy).Methods(http.MethodPost) r.HandleFunc("/async-function/{name:["+NameExpression+"]+}", faasHandlers.QueuedProxy).Methods(http.MethodPost)

View File

@ -14,24 +14,27 @@ type HandlerSet struct {
UpdateFunction http.HandlerFunc UpdateFunction http.HandlerFunc
// QueryFunction - queries the metdata for a function // QueryFunction queries the metdata for a function
QueryFunction http.HandlerFunc QueryFunction http.HandlerFunc
// QueuedProxy - queue work and return synchronous response // QueuedProxy queue work and return synchronous response
QueuedProxy http.HandlerFunc QueuedProxy http.HandlerFunc
// AsyncReport - report a deferred execution result // AsyncReport report a deferred execution result
AsyncReport http.HandlerFunc AsyncReport http.HandlerFunc
// ScaleFunction allows a function to be scaled // ScaleFunction enables a function to be scaled
ScaleFunction http.HandlerFunc ScaleFunction http.HandlerFunc
// InfoHandler provides version and build info // InfoHandler provides version and build info
InfoHandler http.HandlerFunc InfoHandler http.HandlerFunc
// SecretHandler allows secrets to be managed // SecretHandler enables secrets to be managed
SecretHandler http.HandlerFunc SecretHandler http.HandlerFunc
// LogProxyHandler allows streaming of logs for functions // LogProxyHandler enables streaming of logs for functions
LogProxyHandler http.HandlerFunc LogProxyHandler http.HandlerFunc
// NamespaceListerHandler lists namespaces
NamespaceListerHandler http.HandlerFunc
} }

View File

@ -7,11 +7,13 @@ import (
// FaaSHandlers provide handlers for OpenFaaS // FaaSHandlers provide handlers for OpenFaaS
type FaaSHandlers struct { type FaaSHandlers struct {
FunctionReader http.HandlerFunc
DeployHandler http.HandlerFunc
// FunctionProxy provides the function invocation proxy logic. Use proxy.NewHandlerFunc to // FunctionProxy provides the function invocation proxy logic. Use proxy.NewHandlerFunc to
// use the standard OpenFaaS proxy implementation or provide completely custom proxy logic. // use the standard OpenFaaS proxy implementation or provide completely custom proxy logic.
FunctionProxy http.HandlerFunc FunctionProxy http.HandlerFunc
FunctionReader http.HandlerFunc
DeployHandler http.HandlerFunc
DeleteHandler http.HandlerFunc DeleteHandler http.HandlerFunc
ReplicaReader http.HandlerFunc ReplicaReader http.HandlerFunc
ReplicaUpdater http.HandlerFunc ReplicaUpdater http.HandlerFunc
@ -19,10 +21,11 @@ type FaaSHandlers struct {
// LogHandler provides streaming json logs of functions // LogHandler provides streaming json logs of functions
LogHandler http.HandlerFunc LogHandler http.HandlerFunc
// Optional: Update an existing function // UpdateHandler an existing function/service
UpdateHandler http.HandlerFunc UpdateHandler http.HandlerFunc
HealthHandler http.HandlerFunc HealthHandler http.HandlerFunc
InfoHandler http.HandlerFunc InfoHandler http.HandlerFunc
ListNamespaceHandler http.HandlerFunc
} }
// FaaSConfig set config for HTTP handlers // FaaSConfig set config for HTTP handlers