diff --git a/docker/runtime/golang/kubeless.tpl.go b/docker/runtime/golang/kubeless.tpl.go index de4489fdb..699ab447d 100644 --- a/docker/runtime/golang/kubeless.tpl.go +++ b/docker/runtime/golang/kubeless.tpl.go @@ -126,6 +126,7 @@ func handler(w http.ResponseWriter, r *http.Request) { EventNamespace: r.Header.Get("event-namespace"), Extensions: functions.Extension{ Request: r, + Response: w, Context: ctx, }, } diff --git a/docker/runtime/nodejs/kubeless.js b/docker/runtime/nodejs/kubeless.js index 9e66b5fdd..8be50753b 100644 --- a/docker/runtime/nodejs/kubeless.js +++ b/docker/runtime/nodejs/kubeless.js @@ -84,7 +84,7 @@ function modExecute(handler, req, res, end) { 'event-time': req.get('event-time'), 'event-namespace': req.get('event-namespace'), data, - 'extensions': { request: req }, + 'extensions': { request: req, response: res }, }; Promise.resolve(func(event, context)) // Finalize diff --git a/docker/runtime/php/Controller.php b/docker/runtime/php/Controller.php index ee1d91995..88c2983a3 100644 --- a/docker/runtime/php/Controller.php +++ b/docker/runtime/php/Controller.php @@ -40,7 +40,7 @@ public function __construct() * * @return void */ - private function runFunction(Request $request) + private function runFunction(Request $request, Response $response) { set_time_limit($this->timeout); ob_start(); @@ -63,12 +63,14 @@ private function runFunction(Request $request) 'event-namespace' => $_SERVER['HTTP_EVENT_NAMESPACE'], 'extensions' => (object) array( 'request' => $request, + 'response' => $response, ) ); $res = call_user_func($this->function, $event, $this->functionContext); + $event->extensions->response->getBody()->write($res); ob_end_clean(); chdir($this->currentDir); - return $res; + return $event->extensions->response; } else { sleep($this->timeout); posix_kill($pid, SIGKILL); @@ -106,10 +108,8 @@ public function root(Request $request, Response $response, array $args) { try { $this->validate(); - $ret = $this->runFunction($request); - $response->getBody()->write($ret); - return $response; + return $this->runFunction($request, $response); } catch (\Kubeless\TimeoutFunctionException $e) { $res = $response->withStatus(408); diff --git a/docs/kubeless-functions.md b/docs/kubeless-functions.md index 5ccbd4768..0787d0061 100644 --- a/docs/kubeless-functions.md +++ b/docs/kubeless-functions.md @@ -16,6 +16,7 @@ event: event-namespace: "kafkatriggers.kubeless.io" # Event emitter extensions: # Optional parameters request: ... # Reference to the request received + response: ... # Reference to the response to send # (specific properties will depend on the function language) context: function-name: "pubsub-nodejs" diff --git a/kubeless-non-rbac.jsonnet b/kubeless-non-rbac.jsonnet index c91806d88..c6f97d568 100644 --- a/kubeless-non-rbac.jsonnet +++ b/kubeless-non-rbac.jsonnet @@ -106,13 +106,13 @@ local runtime_images ='[ { "name": "node6", "version": "6", - "runtimeImage": "kubeless/nodejs@sha256:61c5a10aacb709c4575a09a4aa28f822b2d008c0dbf4aa0b124705ee9ca143f9", + "runtimeImage": "kubeless/nodejs@sha256:0a8a72af4cc3bfbfd4fe9bd309cbf486e7493d0dc32a691673b3f0d3fae07487", "initImage": "node:6.10" }, { "name": "node8", "version": "8", - "runtimeImage": "kubeless/nodejs@sha256:fc1aa96e55116400ee13d664a655dfb2025ded91858ebfd5fc0c8f0d6b923eba", + "runtimeImage": "kubeless/nodejs@sha256:76ee28dc7e3613845fface2d1c56afc2e6e2c6d6392c724795a7ccc2f5e60582", "initImage": "node:8" } ], @@ -140,7 +140,7 @@ local runtime_images ='[ { "name": "php72", "version": "7.2", - "runtimeImage": "kubeless/php@sha256:4e44ab60f597e93097bf9f5ea91d58bd9c308bf206043db2a9809ec16a8ff2f4", + "runtimeImage": "kubeless/php@sha256:b605bb6b5ae3b1a2a93570939296618904259d7767a14002fa9733e66d59849b", "initImage": "composer:1.6" } ], @@ -155,7 +155,7 @@ local runtime_images ='[ "name": "go1.10", "version": "1.10", "runtimeImage": "kubeless/go@sha256:bf72622344a54e4360f31d3fea5eb9dca2c96fbedc6f0ad7c54f3eb8fb7bd353", - "initImage": "kubeless/go-init@sha256:e262f70639594b3a9e3481843171ecbbe82e84b786825ebe28bc1a3ae89310d3" + "initImage": "kubeless/go-init@sha256:d0812c4e8351bfd95d0574efd23613cff2664d6a57af4ed0a20ebc651382d476" } ], "depName": "Gopkg.toml", diff --git a/pkg/functions/params.go b/pkg/functions/params.go index 87fa86105..c1c9f93ba 100644 --- a/pkg/functions/params.go +++ b/pkg/functions/params.go @@ -23,8 +23,9 @@ import ( // Extension includes a reference to the Event request and its Context (to handle timeouts) type Extension struct { - Request *http.Request - Context context.Context + Request *http.Request + Response http.ResponseWriter + Context context.Context } // Event includes information about the event source