1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-06 15:46:57 +01:00
Files
openshift-docs/modules/serverless-pingsource-kn.adoc
2020-09-30 19:09:02 +00:00

136 lines
3.1 KiB
Plaintext

// Module included in the following assemblies:
//
// * serverless/event_workflows/serverless-pingsource.adoc
[id="serverless-pingsource-kn_{context}"]
= Using a PingSource with the `kn` CLI
The following sections describe how to create, verify and remove a basic PingSource using the `kn` CLI.
.Prerequisites
* You have Knative Serving and Eventing installed.
* You have the `kn` CLI installed.
.Procedure
. To verify that the PingSource is working, create a simple Knative
service that dumps incoming messages to the service's logs:
+
[source,terminal]
----
$ kn service create event-display \
--image quay.io/openshift-knative/knative-eventing-sources-event-display:latest
----
. For each set of ping events that you want to request, create a PingSource in the same namespace as the event consumer:
+
[source,terminal]
----
$ kn source ping create test-ping-source \
--schedule "*/2 * * * *" \
--data '{"message": "Hello world!"}' \
--sink svc:event-display
----
. Check that the controller is mapped correctly by entering the following command and inspecting the output:
+
[source,terminal]
----
$ kn source ping describe test-ping-source
----
+
.Example output
+
[source,terminal]
----
Name: test-ping-source
Namespace: default
Annotations: sources.knative.dev/creator=developer, sources.knative.dev/lastModifier=developer
Age: 15s
Schedule: */2 * * * *
Data: {"message": "Hello world!"}
Sink:
Name: event-display
Namespace: default
Resource: Service (serving.knative.dev/v1)
Conditions:
OK TYPE AGE REASON
++ Ready 8s
++ Deployed 8s
++ SinkProvided 15s
++ ValidSchedule 15s
++ EventTypeProvided 15s
++ ResourcesCorrect 15s
----
.Verfication steps
You can verify that the Kubernetes events were sent to the Knative event sink by looking at the sink pod's logs.
By default, Knative services terminate their pods if no traffic is received within a 60 second period.
The example shown in this guide creates a PingSource that sends a message every 2 minutes, so each message should be observed in a newly created pod.
. Watch for new pods created:
+
[source,terminal]
----
$ watch oc get pods
----
. Cancel watching the pods using Ctrl+C, then look at the logs of the created pod:
+
[source,terminal]
----
$ oc logs $(oc get pod -o name | grep event-display) -c user-container
----
+
.Example output
+
[source,terminal]
----
☁️ cloudevents.Event
Validation: valid
Context Attributes,
specversion: 1.0
type: dev.knative.sources.ping
source: /apis/v1/namespaces/default/pingsources/test-ping-source
id: 99e4f4f6-08ff-4bff-acf1-47f61ded68c9
time: 2020-04-07T16:16:00.000601161Z
datacontenttype: application/json
Data,
{
"message": "Hello world!"
}
----
[id="pingsource-remove-kn_{context}"]
== Remove the PingSource
. Delete the PingSource:
+
[source,terminal]
----
$ kn delete pingsources.sources.knative.dev test-ping-source
----
. Delete the `event-display` service:
+
[source,terminal]
----
$ kn delete service.serving.knative.dev event-display
----