Invoking Knative services from OpenShift Serverless Logic
This document describes how to call Knative services using OpenShift Serverless Logic custom functions. The procedure described in this document is based on the serverless-workflow-custom-function-knative
example application.
For more details about the Knative custom function, see Custom functions for your OpenShift Serverless Logic service.
-
Your OpenShift Serverless Logic application is ready to use.
For more information about building the application container, see Building workflow images using Quarkus CLI. -
Minikube is installed
-
kubectl
command-line tool is installed. Otherwise, Minikube handles it. -
Knative CLI is installed.
For more information, see Install the Knative CLI. -
Knative workflow CLI is installed.
For more information see Serverless Workflow plug-in for Knative CLI. -
(Optional) Quarkus CLI is installed.
For more information, see Building Quarkus Apps with Quarkus command line interface (CLI). -
You have the custom-function-knative-service project deployed on Knative. For more information on how to deploy a Quarkus project to Knative, see the Quarkus Kubernetes extension documentation.
-
Add the
knative-serving
add-on dependency to your workflow project.<dependency> <groupId>org.kie.kogito</groupId> <artifactId>kogito-addons-quarkus-knative-serving</artifactId> </dependency>
-
Discover the name of the Knative service that your workflow will invoke. In a terminal window, run the following command:
kn service list
You should see an output like:
NAME URL LATEST AGE CONDITIONS READY REASON custom-function-knative-service http://custom-function-knative-service.default.10.109.169.193.sslip.io custom-function-knative-service-00001 3h16m 3 OK / 3 True
Save the Knative service name (
custom-function-knative-service
) to use it in the next step. -
Declare the Knative OpenShift Serverless Logic custom function. In the
functions
section of your workflow, add the following:{ "name": "greet", (1) "type": "custom", (2) "operation": "knative:services.v1.serving.knative.dev/custom-function-knative-service?path=/function", (3) }
1 The name of the OpenShift Serverless Logic function 2 Indicates that this function is a custom one 3 The coordinates of the service you want to invoke -
Invoke the declared function. In an
operation
state, add anaction
that references the function you declared in the previous step like the following:"actions": [ { "functionRef": { "refName": "greet", (1) "arguments": { (2) "name": ".name" } } } ]
1 Function’s name 2 The payload that should be sent in the request -
Deploy your workflow service to Knative. For more information on how to deploy a OpenShift Serverless Logic OpenShift Serverless Logic project to Knative, see the Deploying on Kubernetes.
-
Submit a request to the workflow service
curl -X 'POST' \ '<URL>/plainJsonKnativeFunction' \ (1) -H 'accept: */*' \ -H 'Content-Type: application/json' \ -d '{ "name": "Kogito" }'
1 Replace <URL>
with the URL of your deployed workflow serviceYou should see an output like (
id
will change):{"id":"87cf8275-782d-4e0b-a9be-a95f95c9c190","workflowdata":{"name":"Kogito","greeting":"Greetings from Serverless Workflow, Kogito"}}
Sending as CloudEvent
Knative functions support CloudEvent as the message protocol. OpenShift Serverless Logic can create and post CloudEvent messages in functionRef
. For more information see Custom Functions - Sending a CloudEvent.
Found an issue?
If you find an issue or any misleading information, please feel free to report it here. We really appreciate it!