PingSource

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

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

    Example

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

    Create a new namespace called by entering the following command:

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

    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. ports:
    26. - protocol: TCP
    27. port: 80
    28. targetPort: 8080
    29. EOF

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

    1. kubectl create -n pingsource-example -f - <<EOF
    2. apiVersion: sources.knative.dev/v1beta2
    3. kind: PingSource
    4. metadata:
    5. name: test-ping-source
    6. spec:
    7. schedule: "*/1 * * * *"
    8. contentType: "application/json"
    9. data: '{"message": "Hello world!"}'
    10. sink:
    11. ref:
    12. apiVersion: v1
    13. name: event-display
    14. EOF

    Sometimes you may want to send binary data, which cannot be directly serialized in yaml, to downstream. This can be achieved by using dataBase64 as the payload. As the name suggests, dataBase64 should carry data that is base64 encoded.

    Please note that data and dataBase64 cannot co-exist.

    1. cat <<EOF | kubectl create -f -
    2. apiVersion: sources.knative.dev/v1beta2
    3. kind: PingSource
    4. name: test-ping-source-binary
    5. spec:
    6. schedule: "*/2 * * * *"
    7. contentType: "text/plain"
    8. dataBase64: "ZGF0YQ=="
    9. sink:
    10. ref:
    11. apiVersion: serving.knative.dev/v1
    12. kind: Service
    13. name: event-display
    14. EOF

    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-binary
    7. id: a195be33-ff65-49af-9045-0e0711d05e94
    8. time: 2020-11-17T19:48:00.48334181Z
    9. datacontenttype: text/plain
    10. Data,

    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.

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

    Feedback

    Was this page helpful?

    Glad to hear it! Please .