-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Make documentation for PingSource. #2126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9a04cb6
df1f129
c5aa069
36f1838
485eea0
1e2f734
a1e2c7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| --- | ||
| title: "PingSource example" | ||
| linkTitle: "PingSource" | ||
| weight: 10 | ||
| type: "docs" | ||
| --- | ||
|
|
||
| This example shows how to configure PingSource as an event source for | ||
| functions. | ||
|
|
||
| ## Before you begin | ||
|
|
||
| 1. Set up [Knative Serving](../../../serving). | ||
| 1. Set up [Knative Eventing](../../../eventing). | ||
|
|
||
| ## Create a Knative Service | ||
|
|
||
| To verify that `PingSource` is working, create a simple Knative | ||
| Service that dumps incoming messages to its log. | ||
|
|
||
| {{< tabs name="create-service" default="By YAML" >}} | ||
| {{% tab name="By YAML" %}} | ||
| Use following command to create the service from STDIN: | ||
|
|
||
| ```shell | ||
| cat <<EOF | kubectl create -f - | ||
| apiVersion: serving.knative.dev/v1 | ||
| kind: Service | ||
| metadata: | ||
| name: event-display | ||
| spec: | ||
| template: | ||
| spec: | ||
| containers: | ||
| - image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display | ||
| EOF | ||
| ``` | ||
| {{< /tab >}} | ||
|
|
||
| {{% tab name="By filename" %}} | ||
| Use following command to create the service from the `service.yaml` file: | ||
|
|
||
| ```shell | ||
| kubectl apply --filename service.yaml | ||
| ``` | ||
| {{< /tab >}} | ||
| {{< /tabs >}} | ||
|
|
||
| ## Create a PingSource | ||
|
|
||
| For each set of ping events that you want to request, create an Event | ||
| Source in the same namespace as the destination. | ||
|
|
||
| {{< tabs name="create-source" default="By YAML" >}} | ||
| {{% tab name="By YAML" %}} | ||
| Use following command to create the event source from STDIN: | ||
|
|
||
| ```shell | ||
| cat <<EOF | kubectl create -f - | ||
| apiVersion: sources.knative.dev/v1alpha1 | ||
| kind: PingSource | ||
| metadata: | ||
| name: test-ping-source | ||
| spec: | ||
| schedule: "*/2 * * * *" | ||
| data: '{"message": "Hello world!"}' | ||
| sink: | ||
| ref: | ||
| apiVersion: serving.knative.dev/v1 | ||
| kind: Service | ||
| name: event-display | ||
| EOF | ||
| ``` | ||
| {{< /tab >}} | ||
|
|
||
| {{% tab name="By filename" %}} | ||
| Use following command to create the event source from the `ping-source.yaml` file: | ||
|
|
||
| ```shell | ||
| kubectl apply --filename ping-source.yaml | ||
| ``` | ||
| {{< /tab >}} | ||
| {{< /tabs >}} | ||
|
|
||
|
|
||
| ## Verify | ||
|
|
||
| Verify that the message was sent to the Knative eventing system by | ||
| looking at message dumper logs. | ||
|
|
||
| {{< tabs name="view-event" default="kubectl" >}} | ||
| {{% tab name="kubectl" %}} | ||
|
|
||
| Use following command to view the logs of the event-display service: | ||
|
|
||
| ```shell | ||
| kubectl logs -l serving.knative.dev/service=event-display -c user-container --since=10m | ||
| ``` | ||
|
|
||
| {{< /tab >}} | ||
| {{% tab name="kail" %}} | ||
|
|
||
| You can also use [`kail`](https://github.com/boz/kail) instead of `kubectl logs` | ||
| to tail the logs of the subscriber. | ||
|
|
||
| ```shell | ||
| kail -l serving.knative.dev/service=event-display -c user-container --since=10m | ||
| ``` | ||
|
|
||
| {{< /tab >}} | ||
| {{< /tabs >}} | ||
|
|
||
| You should see log lines showing the request headers and body from the source: | ||
|
|
||
| ``` | ||
| ☁️ cloudevents.Event | ||
| Validation: valid | ||
| Context Attributes, | ||
| specversion: 1.0 | ||
| type: dev.knative.sources.ping | ||
| source: /apis/v1/namespaces/default/pingsources/test-ping-source | ||
| id: d8e761eb-30c7-49a3-a421-cd5895239f2d | ||
| time: 2019-12-04T14:24:00.000702251Z | ||
| datacontenttype: application/json | ||
| Data, | ||
| { | ||
| "message": "Hello world!" | ||
| } | ||
| ``` | ||
|
|
||
| ## Cleanup | ||
|
|
||
| You can delete the PingSource instance by entering the following command: | ||
|
|
||
| {{< tabs name="delete-source" default="By name" >}} | ||
| {{% tab name="By name" %}} | ||
| ```shell | ||
| kubectl delete pingsources.sources.knative.dev test-ping-source | ||
| ``` | ||
| {{< /tab >}} | ||
|
|
||
| {{% tab name="By filename" %}} | ||
| ```shell | ||
| kubectl delete --filename ping-source.yaml | ||
| ``` | ||
| {{< /tab >}} | ||
| {{< /tabs >}} | ||
|
|
||
|
|
||
| Similarly, you can delete the Service instance via: | ||
|
|
||
| {{< tabs name="delete-service" default="By name" >}} | ||
| {{% tab name="By name" %}} | ||
| ```shell | ||
| kubectl delete service.serving.knative.dev event-display | ||
| ``` | ||
| {{< /tab >}} | ||
| {{% tab name="By filename" %}} | ||
| ```shell | ||
| kubectl delete --filename service.yaml | ||
| ``` | ||
| {{< /tab >}} | ||
|
|
||
| {{< /tabs >}} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| apiVersion: sources.knative.dev/v1alpha1 | ||
| kind: PingSource | ||
| metadata: | ||
| name: test-ping-source | ||
| spec: | ||
| schedule: "*/2 * * * *" | ||
| data: '{"message": "Hello world!"}' | ||
| sink: | ||
| ref: | ||
| apiVersion: serving.knative.dev/v1 | ||
| kind: Service | ||
| name: event-display |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # This is a very simple Knative Service that writes the input request to its log. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe mention that it's an event input request or something?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is used all over, maybe we can migrate to a central doc to talk about this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe time to resurrect #170 ? |
||
|
|
||
| apiVersion: serving.knative.dev/v1 | ||
| kind: Service | ||
| metadata: | ||
| name: event-display | ||
| spec: | ||
| template: | ||
| spec: | ||
| containers: | ||
| - image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be services or Knative services rather than "functions"?