Skip to content

projectodd/kwsk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kwsk (Apache OpenWhisk on Knative)

This is a prototype of replacing almost the entirety of the Apache OpenWhisk server components with Knative. The goal would be to keep existing OpenWhisk clients, developer tooling, and integrations working unchanged against a new OpenWhisk that builds on top of Knative and Kubernetes exclusively.

Prerequisites

You'll need a recent go and dep. You'll also want this repository checked somewhere under $GOPATH/src.

You'll also need a working Knative installation.

Running the server

dep ensure

You'll need the istio ingress to invoke your actions.

ISTIO=$(minikube ip):$(kubectl get svc knative-ingressgateway -n istio-system -o 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
go run ./cmd/kwsk-server/main.go --port 8080 --istio $ISTIO

For GKE-based Knative, the istio ingress is a LoadBalancer type instead of Nodeport type like it is on minikube. And you have to use port 80. So, if you are using GKE-based Knative do the following:

ISTIO=$(kubectl get svc knative-ingressgateway -n istio-system -o yaml | grep ip | cut -d ":" -f 2):80
go run ./cmd/kwsk-server/main.go --port 8080 --istio $ISTIO

Testing the server

Use curl for a crude test:

curl http://127.0.0.1:8080/api/v1/namespaces/foo/actions

Or via the wsk CLI like:

wsk property set --apihost "http://127.0.0.1:8080"

cat <<EOF >hello.js
function main(params) {
  var name = params.name || 'stranger';
  var greeting = 'Hello ' + name + '!';
  console.log(greeting);
  return {payload: greeting};
}
EOF

wsk action create hello hello.js
wsk action list
wsk action get hello
wsk action invoke hello -r -p name world

kubectl logs $(kubectl get pod | grep hello.*deployment | awk '{print $1}') -c user-container

wsk action create jello test/etc/action.jar --main Hello
wsk action create pello test/etc/action-python.zip --kind=python:default
wsk action create zippy test/etc/action-nodejs.zip --kind=nodejs:default

Automated testing

It's possible to run the upstream OpenWhisk tests against this server using the scripts in the test/bin directory. They rely on a recent version of minikube started with specific options:

./test/bin/minikube-start.sh
./test/bin/knative-install.sh

Once you have knative installed, running the tests is simple:

./test/bin/integs.sh

The default test matching pattern is system.basic.WskRest* but you can override that using the TESTS environment variable, e.g.

TESTS="system.basic.WskRestBasicNode8Tests" ./test/bin/integs.sh

The latest upstream repo is cloned to test/openwhisk so the first time you run integs.sh will take a long time due to compilation. Subsequent runs will be faster since the test/openwhisk directory is not deleted. You can manually delete it, of course, to force a rebuild of the latest upstream OpenWhisk.

Implementing the server

The server just contains a but of stubs and unimplemented code right now. Read through the go-swagger docs to see how to get started with actual implementations.

The handlers for each API call have autogenerated stubs in restapi/configure_kwsk.go. Work has started to move out implementions for each type into their own file, such as restapi/configure_kwsk_actions.go.

The parameters, responses, etc for all actions are strongly typed. You can view the types and their interfaces at restapi/operations/.

Generating the server

This server was generated using go-swagger with the command:

swagger generate server -A Kwsk -P models.Principal -f apiv1swagger.json