PingSource

version

A PingSource produces events with a fixed payload on a specified cron schedule.

Installation

The PingSource source type is enabled by default when you install Knative Eventing.

Example

This example shows how to send an event every second to a Event Display Service.

Creating a namespace

Create a new namespace called pingsource-example by entering the following command:

  1. kubectl create namespace pingsource-example

Creating the Event Display Service

In this step, you create one event consumer, event-display to verify that PingSource is properly working.

To deploy the event-display consumer to your cluster, run the following command:

  1. kubectl -n pingsource-example apply -f - << EOF
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: event-display
  6. spec:
  7. replicas: 1
  8. selector:
  9. matchLabels: &labels
  10. app: event-display
  11. template:
  12. metadata:
  13. labels: *labels
  14. spec:
  15. containers:
  16. - name: event-display
  17. image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
  18. ---
  19. kind: Service
  20. apiVersion: v1
  21. metadata:
  22. name: event-display
  23. spec:
  24. selector:
  25. app: event-display
  26. ports:
  27. - protocol: TCP
  28. port: 80
  29. targetPort: 8080
  30. EOF

Creating the PingSource

You can now create the PingSource sending an event containing {"message": "Hello world!"} every second.

  1. kubectl create -n pingsource-example -f - <<EOF
  2. apiVersion: sources.knative.dev/v1beta1
  3. kind: PingSource
  4. metadata:
  5. name: test-ping-source
  6. spec:
  7. schedule: "*/1 * * * *"
  8. jsonData: '{"message": "Hello world!"}'
  9. sink:
  10. ref:
  11. apiVersion: v1
  12. kind: Service
  13. name: event-display
  14. EOF
  1. kn source ping create test-ping-source \
  2. --namespace pingsource-example
  3. --schedule "*/1 * * * *" \
  4. --data '{"message": "Hello world!"}' \
  5. --sink http://event-display.svc.cluster.local

Verify

View the logs for the event-display event consumer by entering the following command:

  1. kubectl -n pingsource-example logs -l app=event-display --tail=100

This returns the Attributes and Data of the events that the PingSource sent to the event-display Service:

  1. ☁️ cloudevents.Event
  2. Validation: valid
  3. Context Attributes,
  4. specversion: 1.0
  5. type: dev.knative.sources.ping
  6. source: /apis/v1/namespaces/default/pingsources/test-ping-source
  7. id: d8e761eb-30c7-49a3-a421-cd5895239f2d
  8. time: 2019-12-04T14:24:00.000702251Z
  9. datacontenttype: application/json
  10. Data,
  11. {
  12. "message": "Hello world!"
  13. }

Cleanup

Delete the pingsource-example namespace and all of its resources from your cluster by entering the following command:

  1. kubectl delete namespace pingsource-example

Reference Documentation

See the PingSource specification.

Contact

For any inquiries about this source, please reach out on to the Knative users group.