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.

Prerequisites
Procedure
  1. 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>
  2. Enable the Service Discovery feature.

  3. 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.

  4. 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
  5. Invoke the declared function. In an operation state, add an action 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
  6. 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.

  7. 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 service

    You 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!