This example contains a simple workflow service that illustrates how to use Serverless Workflow custom function to invoke Knative services.
This example consists of a workflow and a remote service that both will be deployed to Knative.
The service is described using JSON format as defined in the CNCF Serverless Workflow specification.
You will need:
Execute this command to build the images in your Minikube internal registry.
eval $(minikube -p minikube docker-env --profile knative)
To expose the service URLs in your local environment you must start the minikube tunnel.
# you will be asked for your admin password minikube tunnel --profile knative
# The namespace name is very important to ensure all the services that compose the example can interact. kubectl create ns custom-functions
custom-function-knative-service
project to KnativeFrom the custom-function-knative-service
directory run:
mvn clean package -Dcontainer
kubectl apply -f target/kubernetes/knative.yml
Check if the service was successfully deployed:
kn service list -n custom-functions
You should see something similar to (URL should change):
NAME URL LATEST AGE CONDITIONS READY REASON custom-function-knative-service http://custom-function-knative-service.custom-functions.10.107.55.54.sslip.io custom-function-knative-service-00001 53s 3 OK / 3 True
workflow
project to KnativeFrom the workflow
directory run:
mvn clean package -Dcontainer
kubectl apply -f target/kubernetes/knative.yml
Check if the service was successfully deployed:
kn service list -n custom-functions
You should see both services deployed similar to (URLs should change):
NAME URL LATEST AGE CONDITIONS READY REASON custom-function-knative-service http://custom-function-knative-service.custom-functions.10.107.55.54.sslip.io custom-function-knative-service-00001 9m45s 3 OK / 3 True workflow http://workflow.custom-functions.10.107.55.54.sslip.io workflow-00001 8s 3 OK / 3 True
The service based on the JSON workflow definition can be accessed by sending a request to <URL>/plainJsonKnativeFunction
(replace <URL>
with the URL returned by the above command) with the following content:
{ "name": "Kogito" }
Complete curl command can be found below (replace <URL>
with the URL for the workflow
service returned by the kn service list
command):
curl -X 'POST' \ '<URL>/plainJsonKnativeFunction' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "name": "Kogito" }'
Should return something like this (“id” will change):
{"id":"87cf8275-782d-4e0b-a9be-a95f95c9c190","workflowdata":{"name":"Kogito","greeting":"Greetings from Serverless Workflow, Kogito"}}
The service based on the JSON workflow definition can be accessed by sending a request to <URL>/cloudEventKnativeFunction
(replace <URL>
with the URL returned by the above command) with the following content:
{ "cloudevent": { "specversion": "1.0", "source": "org.acme.source", "type": "test", "data": { "value": "test data" } } }
source
and the workflow instance ID. In case an ID is set, Kogito Serverless Workflow will ignore it and use a generated one.Complete curl command can be found below (replace <URL>
with the URL for the workflow
service returned by the kn service list
command):
curl -X 'POST' \ '<URL>/cloudEventKnativeFunction' \ -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "cloudevent": { "specversion": "1.0", "source": "org.acme.source", "type": "test", "data": { "value": "test data"} }}'
Should return something like this (“id” will change):
{"id":"8dc00353-c1c6-45e9-845d-e9188d103f50","workflowdata":{"id":"response-of-org.acme.source_8dc00353-c1c6-45e9-845d-e9188d103f50","specversion":"1.0","source":"cloudEventFunction","type":"annotated"}}
To remove the installed services from your minikube installation you can use the following command:
# Note: this command might take some seconds. kubectl delete namespace custom-functions