
Deployment
resource, I am going to use the same setup to trigger a function by an event. To keep it continuous with the previous post, I am going to assume that you have completed all the steps of deploying the WordPress application, enabling the Kyma plugin, and have the service registered with the Service Catalog. If this is not the case, please follow the Build a cloud-native extension for WordPress blog post to set up your environment before continuing.Function
is triggered based on its subscription. Achieving this requires a WordPress application to be registered as a Service
in the Service Catalog (Steps covered in the last blog post). Then, only two other custom resource creations are required: a Function
and a Trigger
.Function
Trigger
for the Function
Function
must be written in JavaScript and takes an event
and a context
as parameters.event
parameter represents the event that caused the function to be invokedcontext
parameter represents properties related to the function and the environment informationFunction
can be called using APIRules
, Triggers
, and/or Service Bindings
.APIRule
allows Function
to be exposed externally. This means that the Function
can be a standalone service that gets called without being attached to an event.Trigger
allows Function
to be called by an event trigger. This means that the Function
is not externally exposed and is only accessible by the trigger.Service Binding
allows Function
to be bound to a Service
. This means that the Function
is available for only that specific application and a secret with application environment variables are created to be used by the Function.yaml
file. If you don’t have access to an IDE, this might be a good alternative. However, it doesn’t provide you with the option of testing your code.Function
is created, it creates a ConfigMap
, a Job
, a Deployment
, a Service
, and a HorizontalPodAutoscaler
ConfigMap
contains your codeJob
creates a docker image based on the code and pushes to a Docker registryDeployment
with the Function
image created by the Job
is createdService
for the Deployment
is createdApplication
custom resource creates resources for eventing by default. Kyma will take care of creating all resources related to an application so that when necessary, the eventing component can be utilized. One resource that is important to note is the creation of the Broker
. An event is sent to the Broker
and is forwarded to a Subscriber
, which in this example is the Function
.subscriptions
resources in the Kyma environment. Use the following code to list either Knative or Kyma subscription resources.kubectl get subscriptions.messaging.knative.dev –all-namespaces
kubectl get subscriptions.messaging.knative.dev –all-namespaces
Trigger
custom resource is created using a yaml
file via command line instead of the console, I ran into a problem where Trigger
custom resource never became “Ready” and received the following message: “Unable to get the Subscriber's URI”.Trigger
does not work for you, try listing the resourceapiVersion
version to v1
instead of serving.knative.dev/v1
Broker
and Trigger
components might be useful. In a very high level, both Broker
and Trigger
enables the filtering of events.Broker
receives events and forward it to the Subscribers
based on the Trigger
.Trigger
allows filtering events and makes sure that Subscriber
receives only the event they want.{"code":405,"error":"Method not allowed."}
when trying to curl the /v1/events
endpoint. Therefore, I used the WordPress blog post to go through the steps necessary to test out the eventing components.Function
instead of copying and pasting an example from the tutorial. You can always start with simple “Hello World” and add on from there.module.exports = {
main: function (event, context) {
console.log("Hello World");
return "Hello World!";
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.