Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions eventing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
85 changes: 85 additions & 0 deletions eventing/samples/cronjob-source/README.md
Original file line number Diff line number Diff line change
@@ -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!\"}"
}
```
11 changes: 11 additions & 0 deletions eventing/samples/cronjob-source/cronjob-source.yaml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions eventing/samples/cronjob-source/service.yaml
Original file line number Diff line number Diff line change
@@ -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