From 8f0d2d1fd6c5e3c9d2e0a73d6d256c4e232b3737 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (VMware)" Date: Mon, 23 Jul 2018 15:23:02 +0100 Subject: [PATCH] Expose scale-function endpoint - exposes scale-function endpoint for use with faas-idler, this is protected by auth when enabled. Signed-off-by: Alex Ellis (VMware) --- api-docs/swagger.yml | 27 +++++++++++++++++++++++++++ gateway/server.go | 6 ++++++ gateway/types/handler_set.go | 3 +++ 3 files changed, 36 insertions(+) diff --git a/api-docs/swagger.yml b/api-docs/swagger.yml index a1a9b807..a36bedc9 100644 --- a/api-docs/swagger.yml +++ b/api-docs/swagger.yml @@ -197,6 +197,33 @@ paths: description: Function not found '500': description: Error connecting to function + '/system/scale-function/{functionName}': + get: + summary: Scale a function + parameters: + - in: path + name: functionName + description: Function name + type: string + required: true + - in: body + name: input + description: Function to scale plus replica count + schema: + type: string + format: binary + example: + '{"service": "hello-world", "replicas": 10}' + required: false + responses: + '200': + description: Scaling OK + '202': + description: Scaling OK + '404': + description: Function not found + '500': + description: Error scaling function '/system/function/{functionName}': get: summary: Get a summary of an OpenFaaS function diff --git a/gateway/server.go b/gateway/server.go index 8d533ad2..4834672c 100644 --- a/gateway/server.go +++ b/gateway/server.go @@ -101,6 +101,8 @@ func main() { faasHandlers.ListFunctions = metrics.AddMetricsHandler(faasHandlers.ListFunctions, prometheusQuery) faasHandlers.Proxy = handlers.MakeCallIDMiddleware(faasHandlers.Proxy) + faasHandlers.ScaleFunction = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver) + if credentials != nil { faasHandlers.UpdateFunction = handlers.DecorateWithBasicAuth(faasHandlers.UpdateFunction, credentials) @@ -110,6 +112,9 @@ func main() { handlers.DecorateWithBasicAuth(faasHandlers.DeployFunction, credentials) faasHandlers.ListFunctions = handlers.DecorateWithBasicAuth(faasHandlers.ListFunctions, credentials) + faasHandlers.ScaleFunction = + handlers.DecorateWithBasicAuth(faasHandlers.ScaleFunction, credentials) + } r := mux.NewRouter() @@ -141,6 +146,7 @@ func main() { r.HandleFunc("/system/functions", faasHandlers.DeployFunction).Methods(http.MethodPost) r.HandleFunc("/system/functions", faasHandlers.DeleteFunction).Methods(http.MethodDelete) r.HandleFunc("/system/functions", faasHandlers.UpdateFunction).Methods(http.MethodPut) + r.HandleFunc("/system/scale-function/{name:[-a-zA-Z_0-9]+}", faasHandlers.ScaleFunction).Methods(http.MethodPost) if faasHandlers.QueuedProxy != nil { r.HandleFunc("/async-function/{name:[-a-zA-Z_0-9]+}/", faasHandlers.QueuedProxy).Methods(http.MethodPost) diff --git a/gateway/types/handler_set.go b/gateway/types/handler_set.go index 79bbd5d4..80e5bb63 100644 --- a/gateway/types/handler_set.go +++ b/gateway/types/handler_set.go @@ -17,4 +17,7 @@ type HandlerSet struct { // AsyncReport - report a deferred execution result AsyncReport http.HandlerFunc + + // ScaleFunction allows a function to be scaled + ScaleFunction http.HandlerFunc }