diff --git a/eventing/README.md b/eventing/README.md index bdb3343999c..6bbdfa47e55 100644 --- a/eventing/README.md +++ b/eventing/README.md @@ -209,6 +209,19 @@ FTP server for new files or generate events at a set time interval. [ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.12/#objectreference-v1-core) A reference to the object that should receive events. +### CronJobSource + +The CronJobSource fires events based on given [Cron](https://en.wikipedia.org/wiki/Cron) schedule. + +**Spec fields**: + +- `schedule` (**required**): `string` A [Cron](https://en.wikipedia.org/wiki/Cron) format string, such as `0 * * * *` or `@hourly`. +- `data`: `string` Optional data sent to downstream receiver. +- `serviceAccountName`: `string` The name of the ServiceAccount to run the container as. +- `sink`: + [ObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.12/#objectreference-v1-core) + A reference to the object that should receive events. + ## Getting Started - [Setup Knative Serving](../install/README.md) diff --git a/eventing/samples/cronjob-source/README.md b/eventing/samples/cronjob-source/README.md new file mode 100644 index 00000000000..1e5c4a8d697 --- /dev/null +++ b/eventing/samples/cronjob-source/README.md @@ -0,0 +1,85 @@ +# Cron Job Source example + +Cron Job Source example shows how to configure Cron Job as event source for +functions. + +## Deployment Steps + +### Prerequisites + +1. Setup [Knative Serving](https://github.com/knative/docs/tree/master/serving). +1. Setup + [Knative Eventing](https://github.com/knative/docs/tree/master/eventing). + +### Create a Knative Service + +In order to verify `CronJobSource` is working, we will create a simple Knative +Service that dumps incoming messages to its log. + +```yaml +apiVersion: serving.knative.dev/v1alpha1 +kind: Service +metadata: + name: message-dumper +spec: + runLatest: + configuration: + revisionTemplate: + spec: + container: + image: github.com/knative/eventing-sources/cmd/message_dumper +``` + +Use following command to create the service from `service.yaml`: + +```shell +kubectl apply -f service.yaml +``` + +### Create Cron Job Event Source + +For each set of cron events you want to request, you need to create an Event +Source in the same namespace as the destiantion. If you need a different +ServiceAccount to create the Deployment, modify the entry accordingly in the +yaml. + +```yaml +apiVersion: sources.eventing.knative.dev/v1alpha1 +kind: CronJobSource +metadata: + name: test-cronjob-source +spec: + schedule: "*/2 * * * *" + data: '{"message": "Hello world!"}' + sink: + apiVersion: serving.knative.dev/v1alpha1 + kind: Service + name: message-dumper +``` + +Use following command to create the event source from `cronjob-source.yaml`: + +```shell +kubectl apply -f cronjob-source.yaml +``` + +### Verify + +We will verify that the message was sent to the Knative eventing system by +looking at message dumper logs. + +1. Use [`kail`](https://github.com/boz/kail) to tail the logs of the subscriber. + + ```shell + kail -d message-dumper -c user-container --since=10m + ``` + +You should see log lines similar to: + +```json +{ + "ID": "1543616460000180552-203", + "EventTime": "2018-11-30T22:21:00.000186721Z", + "Body": "{\"message\": \"Hello world!\"}" +} +``` diff --git a/eventing/samples/cronjob-source/cronjob-source.yaml b/eventing/samples/cronjob-source/cronjob-source.yaml new file mode 100644 index 00000000000..67c6911d0c7 --- /dev/null +++ b/eventing/samples/cronjob-source/cronjob-source.yaml @@ -0,0 +1,11 @@ +apiVersion: sources.eventing.knative.dev/v1alpha1 +kind: CronJobSource +metadata: + name: test-cronjob-source +spec: + schedule: "*/2 * * * *" + data: '{"message": "Hello world!"}' + sink: + apiVersion: serving.knative.dev/v1alpha1 + kind: Service + name: message-dumper diff --git a/eventing/samples/cronjob-source/service.yaml b/eventing/samples/cronjob-source/service.yaml new file mode 100644 index 00000000000..172a25fad14 --- /dev/null +++ b/eventing/samples/cronjob-source/service.yaml @@ -0,0 +1,13 @@ +# This is a very simple Knative Service that writes the input request to its log. + +apiVersion: serving.knative.dev/v1alpha1 +kind: Service +metadata: + name: message-dumper +spec: + runLatest: + configuration: + revisionTemplate: + spec: + container: + image: github.com/knative/eventing-sources/cmd/message_dumper