This is the typical process for running each of the tests under this directory.
kubectl get buildtemplate NAME CREATED AT openwhisk-nodejs-runtime 10m
export DOCKER_USERNAME="myusername" sed 's/${DOCKER_USERNAME}/'"$DOCKER_USERNAME"'/' build.yaml.tmpl > build.yaml kubectl apply -f build.yaml
export DOCKER_USERNAME="myusername" sed 's/${DOCKER_USERNAME}/'"$DOCKER_USERNAME"'/' service.yaml.tmpl > service.yaml kubectl apply -f service.yaml
Depending on the value you set in buildtemplate.yaml for the OW_RUNTIME_PLATFORM
parameter, you will need to invoke different endpoints to execute the test.
Currently, the following platform (values) are supported:
Under the Knative platform, the developer has 2 choices:
The test case cases under this directory presume option 2 (“stem cells”) where both the both runtime initialization, as well as function execution (Activation) happen sequentially.
However, as OW runtimes do not allow “re-initialization” at this time, once you send the “init data” once to the runtime you cannot send it again or it will result in an error.
Below are some options for invoking the endpoint (route) manually using common developer tooling in conjunction with prepared data:
Simply send the “init-run” data to the base ‘/’ route on the runtime (service) endpoint.
If your function requires no input data on the request:
curl -H "Host: <hostname>" -X POST http://localhost/
otherwise, you can supply the request data and Content-Type
on the command and pass the JSON data to your function via data file:
curl -H "Host: <hostname>" -d "@data-init-run.json" -H "Content-Type: application/json" http://localhost/
If using an IDE such as VSCode or IntelliJ you can simply “run” the HTTP payload files named ‘payload-knative-init-run.http’ which both initializes the runtime with the function and configuration and executes the function with the provided “values” data.
For example, the HelloWorld with parameters payload looks like this:
POST http://localhost:8080/ HTTP/1.1 content-type: application/json { "init": { "name": "nodejs-helloworld", "main": "main", "binary": false, "code": "function main() {return {payload: 'Hello World!'};}" }, "activation": { "namespace": "default", "action_name": "nodejs-helloworld", "api_host": "", "api_key": "", "activation_id": "", "deadline": "4102498800000" }, "value": { "name": "Joe", "place": "TX" } }
please note that the “activation” data is also provided, but defaulted in most cases as these would be provided by a control-plane which would manage pools of the runtimes and track Activations.
The standard OW methods used to run functions is done through calls to 2 separte endpoints. In short, The control plane would:
Below are some options for invoking these routes manually using common developer tooling in conjunction with prepared data:
Initialize the runtime with the function and other configuration data using the /init
endpoint.
curl -H "Host: <hostname>" -d "@data-init.json" -H "Content-Type: application/json" http://localhost/init
Execute the function using the /run
endpoint.
with no request data:
curl -H "Host: <hostname>" -X POST http://localhost/run
or with request data and its Content-Type
:
curl -H "Host: <hostname>" -d "@data-run.json" -H "Content-Type: <content-type>" -X POST http://localhost/run
In some cases, you may need to force the pod to be deleted when the normal delete shown below does not work.
# Normal service delete kubectl delete -f service.yaml
you will see something like the following for a long period of time:
$ kubectl get pods --namespace default NAME READY STATUS RESTARTS AGE nodejs-helloworld-00001-deployment-78c6bfbf4c-8cgtd 2/3 Terminating 0 81s
In this case, you can force the pod with your service to delete as follows:
kubectl delete pod nodejs-helloworld-00001-deployment-78c6bfbf4c-8cgtd --grace-period=0 --force
Also, be sure your service is completely deleted from the system:
kubectl delete -f service.yaml