vmware-archive / functions

Functions Repository for Kubeless
Apache License 2.0
70 stars 37 forks source link

Do we have any working examples of nodejs functions? #14

Closed sayanh closed 7 years ago

sayanh commented 7 years ago

Although I am using the following function from https://github.com/kubeless/kubeless/tree/master/examples/nodejs:

module.exports = {
  foo: function (req, res) {
        res.end('hello world')

  }
}

it does not seem to be working.

Deploying in kubeless as follows: kubeless function update testjs --runtime nodejs8 --handler testjs.foo --from-file hello.js --namespace kubeless

Following are my issues: 1) The function gets deployed with a default topic as kubeless which I had to create in kafka later. Can I not deploy a function without a topic the way I did for Python?

2) But I am not able to invoke a js function : Invoking as:

kubeless function call testjs --data '{"echo": "echo echo"}' --namespace kubeless

and below is what I see in pod logs:

::ffff:127.0.0.1 - - [17/Oct/2017:12:57:14 +0000] "POST / HTTP/1.1" 404 140 "-" "Go-http-client/1.1"
::ffff:127.0.0.1 - - [17/Oct/2017:13:03:32 +0000] "GET / HTTP/1.1" 404 139 "-" "Go-http-client/1.1"

and output as:

Connecting to function...
Forwarding from 127.0.0.1:30000 -> 8080
Forwarding from [::1]:30000 -> 8080
Handling connection for 30000

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST </pre>
</body>
</html>
sebgoa commented 7 years ago

cc @andresmgot

andresmgot commented 7 years ago

hi @sayanh,

by default the command sets the function trigger as PubSub so it is only possible to trigger it using Kafka messages, in case you want to call it with the kubeless function call command you need to specify --trigger-http when deploying your function:

kubeless function deploy testjs --runtime nodejs8 --handler hello.foo --from-file hello.js --namespace kubeless --trigger-http

This behavior may be indeed confusing, I opened https://github.com/kubeless/kubeless/issues/385 to modify that.

sayanh commented 7 years ago

Thanks, it works fine now!