Flow v1beta1 (#2264)

* update example to use v1beta1 api

* WIP: update flow doc to v1beta1

* update pictures

* fix links
This commit is contained in:
Lionel Villard 2020-03-03 16:04:53 -05:00 committed by GitHub
parent e144a1a7a4
commit 13414d2aff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 168 additions and 206 deletions

View File

@ -6,7 +6,7 @@ type: "docs"
--- ---
We are going to create the following logical configuration. We create a We are going to create the following logical configuration. We create a
CronJobSource, feeding events to a [`Sequence`](../../../sequence.md), then PingSource, feeding events to a [`Sequence`](../../../flows/sequence.md), then
taking the output of that `Sequence` and displaying the resulting output. taking the output of that `Sequence` and displaying the resulting output.
![Logical Configuration](./sequence-reply-to-event-display.png) ![Logical Configuration](./sequence-reply-to-event-display.png)
@ -86,13 +86,13 @@ If you are using a different type of Channel, you need to change the
spec.channelTemplate to point to your desired Channel. spec.channelTemplate to point to your desired Channel.
```yaml ```yaml
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: sequence name: sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:
@ -142,28 +142,28 @@ your resources to be created.
kubectl -n default create -f ./event-display.yaml kubectl -n default create -f ./event-display.yaml
``` ```
### Create the CronJobSource targeting the Sequence ### Create the PingSource targeting the Sequence
This will create a CronJobSource which will send a CloudEvent with {"message": This will create a PingSource which will send a CloudEvent with {"message":
"Hello world!"} as the data payload every 2 minutes. "Hello world!"} as the data payload every 2 minutes.
```yaml ```yaml
apiVersion: sources.eventing.knative.dev/v1alpha1 apiVersion: sources.knative.dev/v1alpha1
kind: CronJobSource kind: PingSource
metadata: metadata:
name: cronjob-source name: ping-source
spec: spec:
schedule: "*/2 * * * *" schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}' data: '{"message": "Hello world!"}'
sink: sink:
ref: ref:
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
name: sequence name: sequence
``` ```
```shell ```shell
kubectl -n default create -f ./cron-source.yaml kubectl -n default create -f ./ping-source.yaml
``` ```
### Inspecting the results ### Inspecting the results
@ -175,19 +175,22 @@ pods.
kubectl -n default get pods kubectl -n default get pods
``` ```
Then look at the logs for the event-display pod: Wait a bit and then look at the logs for the event-display pod:
```shell ```shell
kubectl -n default logs -l serving.knative.dev/service=event-display -c user-container kubectl -n default logs -l serving.knative.dev/service=event-display -c user-container --tail=-1
☁️ cloudevents.Event ☁️ cloudevents.Event
Validation: valid Validation: valid
Context Attributes, Context Attributes,
cloudEventsVersion: 0.1 specversion: 1.0
eventType: samples.http.mod3 type: samples.http.mode3
source: /transformer/2 source: /apis/v1/namespaces/default/pingsources/ping-source
eventID: df52b47e-02fd-45b2-8180-dabb572573f5 id: e8fa7906-ab62-4e61-9c13-a9406e2130a9
eventTime: 2019-06-18T14:18:42.478140635Z time: 2020-03-02T20:52:00.0004957Z
contentType: application/json datacontenttype: application/json
Extensions,
knativehistory: sequence-kn-sequence-0-kn-channel.default.svc.cluster.local; sequence-kn-sequence-1-kn-channel.default.svc.cluster.local; sequence-kn-sequence-2-kn-channel.default.svc.cluster.local
traceparent: 00-6e2947379387f35ddc933b9190af16ad-de3db0bc4e442394-00
Data, Data,
{ {
"id": 0, "id": 0,
@ -195,5 +198,5 @@ Data,
} }
``` ```
And you can see that the initial Cron Source message ("Hello World!") has been And you can see that the initial PingSource message `("Hello World!")` has been
appended to it by each of the steps in the Sequence. appended to it by each of the steps in the Sequence.

View File

@ -6,4 +6,4 @@ spec:
template: template:
spec: spec:
containers: containers:
- image: gcr.io/knative-releases/knative.dev/eventing-sources/cmd/event_display - image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display

View File

@ -1,12 +1,12 @@
apiVersion: sources.eventing.knative.dev/v1alpha1 apiVersion: sources.knative.dev/v1alpha1
kind: CronJobSource kind: PingSource
metadata: metadata:
name: cronjob-source name: ping-source
spec: spec:
schedule: "*/2 * * * *" schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}' data: '{"message": "Hello world!"}'
sink: sink:
ref: ref:
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
name: sequence name: sequence

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -1,10 +1,10 @@
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: sequence name: sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:

View File

@ -37,4 +37,6 @@ spec:
env: env:
- name: MESSAGE - name: MESSAGE
value: " - Handled by 2" value: " - Handled by 2"
- name: TYPE
value: "samples.http.mod3"
--- ---

View File

@ -6,7 +6,7 @@ type: "docs"
--- ---
We are going to create the following logical configuration. We create a We are going to create the following logical configuration. We create a
CronJobSource, feeding events to a [`Sequence`](../../../sequence.md), then PingSource, feeding events to a [`Sequence`](../../../flows/sequence.md), then
taking the output of that `Sequence` and sending it to a second `Sequence` and taking the output of that `Sequence` and sending it to a second `Sequence` and
finally displaying the resulting output. finally displaying the resulting output.
@ -17,9 +17,9 @@ The functions used in these examples live in
## Prerequisites ## Prerequisites
For this example, we'll assume you have set up a an `InMemoryChannel` as well as For this example, we'll assume you have set up an `InMemoryChannel` as well as
Knative Serving (for our functions). The examples use `default` namespace, Knative Serving (for our functions). The examples use `default` namespace,
again, if you want to deploy to another Namespace, you will need to modify the again, if you want to deploy to another namespace, you will need to modify the
examples to reflect this. examples to reflect this.
If you want to use different type of `Channel`, you will have to modify the If you want to use different type of `Channel`, you will have to modify the
@ -127,13 +127,13 @@ If you are using a different type of Channel, you need to change the
spec.channelTemplate to point to your desired Channel. spec.channelTemplate to point to your desired Channel.
```yaml ```yaml
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: first-sequence name: first-sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:
@ -169,13 +169,13 @@ If you are using a different type of Channel, you need to change the
spec.channelTemplate to point to your desired Channel. spec.channelTemplate to point to your desired Channel.
```yaml ```yaml
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: second-sequence name: second-sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:
@ -197,6 +197,11 @@ spec:
name: event-display name: event-display
``` ```
```shell
kubectl -n default create -f ./sequence2.yaml
```
### Create the Service displaying the events created by Sequence ### Create the Service displaying the events created by Sequence
```yaml ```yaml
@ -208,7 +213,7 @@ spec:
template: template:
spec: spec:
containerers: containerers:
- image: gcr.io/knative-releases/knative.dev/eventing-sources/cmd/event_display - image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
``` ```
Change `default` below to create the `Sequence` in the Namespace where you want Change `default` below to create the `Sequence` in the Namespace where you want
@ -218,28 +223,28 @@ your resources created.
kubectl -n default create -f ./event-display.yaml kubectl -n default create -f ./event-display.yaml
``` ```
### Create the CronJobSource targeting the first Sequence ### Create the PingSource targeting the first Sequence
This will create a CronJobSource which will send a CloudEvent with {"message": This will create a PingSource which will send a CloudEvent with `{"message":
"Hello world!"} as the data payload every 2 minutes. "Hello world!"}` as the data payload every 2 minutes.
```yaml ```yaml
apiVersion: sources.eventing.knative.dev/v1alpha1 apiVersion: sources.knative.dev/v1alpha1
kind: CronJobSource kind: PingSource
metadata: metadata:
name: cronjob-source name: ping-source
spec: spec:
schedule: "*/2 * * * *" schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}' data: '{"message": "Hello world!"}'
sink: sink:
ref: ref:
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
name: first-sequence name: first-sequence
``` ```
```shell ```shell
kubectl -n default create -f ./cron-source.yaml kubectl -n default create -f ./ping-source.yaml
``` ```
### Inspecting the results ### Inspecting the results
@ -254,16 +259,19 @@ kubectl -n default get pods
Then look at the logs for the event-display pod: Then look at the logs for the event-display pod:
```shell ```shell
kubectl -n default logs -l serving.knative.dev/service=event-display -c user-container kubectl -n default logs -l serving.knative.dev/service=event-display -c user-container --tail=-1
☁️ cloudevents.Event ☁️ cloudevents.Event
Validation: valid Validation: valid
Context Attributes, Context Attributes,
cloudEventsVersion: 0.1 specversion: 1.0
eventType: samples.http.mod3 type: dev.knative.sources.ping
source: /transformer/5 source: /apis/v1/namespaces/default/pingsources/ping-source
eventID: 7628a147-ec74-43d5-a888-8384a1b6b005 id: 29d531df-78d8-4d11-9ffd-ba24045241a9
eventTime: 2019-06-18T13:57:20.279354375Z time: 2020-03-02T21:18:00.0011708Z
contentType: application/json datacontenttype: application/json
Extensions,
knativehistory: first-sequence-kn-sequence-0-kn-channel.default.svc.cluster.local; first-sequence-kn-sequence-1-kn-channel.default.svc.cluster.local; first-sequence-kn-sequence-2-kn-channel.default.svc.cluster.local; second-sequence-kn-sequence-0-kn-channel.default.svc.cluster.local; second-sequence-kn-sequence-1-kn-channel.default.svc.cluster.local; second-sequence-kn-sequence-2-kn-channel.default.svc.cluster.local
traceparent: 00-e5abc9de525a89ead80560b8f328de5c-fc12b64a6296f541-00
Data, Data,
{ {
"id": 0, "id": 0,
@ -271,5 +279,5 @@ Data,
} }
``` ```
And you can see that the initial Cron Source message ("Hello World!") has been And you can see that the initial PingSource message `("Hello World!")` has been
appended to it by each of the steps in the Sequence. appended to it by each of the steps in the Sequence.

View File

@ -6,4 +6,4 @@ spec:
template: template:
spec: spec:
containers: containers:
- image: gcr.io/knative-releases/knative.dev/eventing-sources/cmd/event_display - image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display

View File

@ -1,12 +1,12 @@
apiVersion: sources.eventing.knative.dev/v1alpha1 apiVersion: sources.knative.dev/v1alpha1
kind: CronJobSource kind: PingSource
metadata: metadata:
name: cronjob-source name: ping-source
spec: spec:
schedule: "*/2 * * * *" schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}' data: '{"message": "Hello world!"}'
sink: sink:
ref: ref:
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
name: first-sequence name: first-sequence

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -1,10 +1,10 @@
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: first-sequence name: first-sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:
@ -22,5 +22,5 @@ spec:
reply: reply:
ref: ref:
kind: Sequence kind: Sequence
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
name: second-sequence name: second-sequence

View File

@ -1,10 +1,10 @@
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: second-sequence name: second-sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:

View File

@ -6,7 +6,7 @@ type: "docs"
--- ---
We are going to create the following logical configuration. We create a We are going to create the following logical configuration. We create a
CronJobSource, feeding events to a [`Sequence`](../../../sequence.md). Sequence CronJobSource, feeding events to a [`Sequence`](../../../flows/sequence.md). Sequence
can then do either external work, or out of band create additional events. can then do either external work, or out of band create additional events.
![Logical Configuration](./sequence-terminal.png) ![Logical Configuration](./sequence-terminal.png)
@ -85,13 +85,13 @@ If you are using a different type of Channel, you need to change the
spec.channelTemplate to point to your desired Channel. spec.channelTemplate to point to your desired Channel.
```yaml ```yaml
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: sequence name: sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:
@ -115,22 +115,22 @@ the resources to be created.
kubectl -n default create -f ./sequence.yaml kubectl -n default create -f ./sequence.yaml
``` ```
### Create the CronJobSource targeting the Sequence ### Create the PingSource targeting the Sequence
This will create a CronJobSource which will send a CloudEvent with {"message": This will create a PingSource which will send a CloudEvent with `{"message":
"Hello world!"} as the data payload every 2 minutes. "Hello world!"}` as the data payload every 2 minutes.
```yaml ```yaml
apiVersion: sources.eventing.knative.dev/v1alpha1 apiVersion: sources.knative.dev/v1alpha1
kind: CronJobSource kind: PingSource
metadata: metadata:
name: cronjob-source name: ping-source
spec: spec:
schedule: "*/2 * * * *" schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}' data: '{"message": "Hello world!"}'
sink: sink:
ref: ref:
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
name: sequence name: sequence
``` ```
@ -139,13 +139,13 @@ Here, if you are using different type of Channel, you need to change the
spec.channelTemplate to point to your desired Channel. spec.channelTemplate to point to your desired Channel.
```shell ```shell
kubectl -n default create -f ./cron-source.yaml kubectl -n default create -f ./ping-source.yaml
``` ```
### Inspecting the results ### Inspecting the results
You can now see the final output by inspecting the logs of the event-display You can now see the final output by inspecting the logs of the event-display
pods. Note that since we set the `CronJobSource` to emit every 2 minutes, it pods. Note that since we set the `PingSource` to emit every 2 minutes, it
might take some time for the events to show up in the logs. might take some time for the events to show up in the logs.
```shell ```shell
@ -155,104 +155,41 @@ kubectl -n default get pods
Let's look at the logs for the first `Step` in the `Sequence`: Let's look at the logs for the first `Step` in the `Sequence`:
```shell ```shell
kubectl -n default logs --tail=50 -l serving.knative.dev/service=first -c user-container kubectl -n default logs -l serving.knative.dev/service=first -c user-container --tail=-1
Got Event Context: Context Attributes,
specversion: 0.2
type: dev.knative.cronjob.event
source: /apis/v1/namespaces/default/cronjobsources/cronjob-source
id: 2fdf69ec-0480-463a-92fb-8d1259550f32
time: 2019-06-18T14:38:00.000379084Z
contenttype: application/json
Extensions,
knativehistory: sequence-kn-sequence-0-kn-channel.default.svc.cluster.local
2019/06/18 14:38:14 http: superfluous response.WriteHeader call from github.com/vaikas-google/transformer/vendor/github.com/cloudevents/sdk-go/pkg/cloudevents/transport/http.(*Transport).ServeHTTP (transport.go:446)
Got Data: &{Sequence:0 Message:Hello world!} 2020/03/02 21:28:00 listening on 8080, appending " - Handled by 0" to events
Got Transport Context: Transport Context, 2020/03/02 21:28:01 Received a new event:
URI: / 2020/03/02 21:28:01 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world!}
Host: first.default.svc.cluster.local 2020/03/02 21:28:01 Transform the event to:
Method: POST 2020/03/02 21:28:01 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world! - Handled by 0}
Header:
X-Request-Id: 9b51bcaa-10bc-97a5-a288-dde9b97f6e1e
Content-Length: 26
K-Proxy-Request: activator
X-Forwarded-For: 10.16.3.77, 127.0.0.1, 127.0.0.1
X-Forwarded-Proto: http
Ce-Knativehistory: sequence-kn-sequence-0-kn-channel.default.svc.cluster.local
X-B3-Spanid: 42bcd58bd1ea8191
X-B3-Parentspanid: c63efd989dcf5dc5
X-B3-Sampled: 0
X-B3-Traceid: 4a1da6622ecbbdea0c75ae32e065cfcb
----------------------------
``` ```
Then we can look at the output of the second Step in the `Sequence`: Then we can look at the output of the second Step in the `Sequence`:
```shell ```shell
kubectl -n default logs --tail=50 -l serving.knative.dev/service=second -c user-container kubectl -n default logs -l serving.knative.dev/service=second -c user-container --tail=-1
Got Event Context: Context Attributes,
cloudEventsVersion: 0.1
eventType: samples.http.mod3
source: /transformer/0
eventID: 5a9ec173-5224-41a2-9c83-50786651bcd5
eventTime: 2019-06-18T14:38:14.657008072Z
contentType: application/json
Got Data: &{Sequence:0 Message:Hello world! - Handled by 0} 2020/03/02 21:28:02 listening on 8080, appending " - Handled by 1" to events
Got Transport Context: Transport Context, 2020/03/02 21:28:02 Received a new event:
URI: / 2020/03/02 21:28:02 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world! - Handled by 0}
Host: second.default.svc.cluster.local 2020/03/02 21:28:02 Transform the event to:
Method: POST 2020/03/02 21:28:02 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world! - Handled by 0 - Handled by 1}
Header:
X-Forwarded-For: 10.16.3.77, 127.0.0.1, 127.0.0.1
X-Forwarded-Proto: http
Content-Length: 48
X-B3-Sampled: 0
Ce-Knativehistory: sequence-kn-sequence-1-kn-channel.default.svc.cluster.local
X-B3-Parentspanid: 4fba491a605b2391
K-Proxy-Request: activator
X-B3-Spanid: 56e4150c4e1d679b
X-B3-Traceid: fb468aa8ec035a66153ce3f4929aa2fe
X-Request-Id: d60e7109-3853-9ca1-83e2-c70f8cbfbb93
----------------------------
``` ```
And you can see that the initial Cron Source message ("Hello World!") has now And you can see that the initial PingSource message `("Hello World!")` has now
been modified by the first step in the Sequence to include " - Handled by 0". been modified by the first step in the Sequence to include " - Handled by 0".
Exciting :) Exciting :)
Then we can look at the output of the last Step in the `Sequence`: Then we can look at the output of the last Step in the `Sequence`:
```shell ```shell
kubectl -n default logs --tail=50 -l serving.knative.dev/service=third -c user-container kubectl -n default logs -l serving.knative.dev/service=third -c user-container --tail=-1
Got Event Context: Context Attributes,
cloudEventsVersion: 0.1
eventType: samples.http.mod3
source: /transformer/1
eventID: 5747fb77-66a2-4e78-944b-43192aa879fb
eventTime: 2019-06-18T14:38:32.688345694Z
contentType: application/json
Got Data: &{Sequence:0 Message:Hello world! - Handled by 0 - Handled by 1} 2020/03/02 21:28:03 listening on 8080, appending " - Handled by 2" to events
Got Transport Context: Transport Context, 2020/03/02 21:28:03 Received a new event:
URI: / 2020/03/02 21:28:03 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world! - Handled by 0 - Handled by 1}
Host: third.default.svc.cluster.local 2020/03/02 21:28:03 Transform the event to:
Method: POST 2020/03/02 21:28:03 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world! - Handled by 0 - Handled by 1 - Handled by 2}
Header:
X-B3-Sampled: 0
X-B3-Traceid: 64a9c48c219375476ffcdd5eb14ec6e0
X-Forwarded-For: 10.16.3.77, 127.0.0.1, 127.0.0.1
X-Forwarded-Proto: http
Ce-Knativehistory: sequence-kn-sequence-2-kn-channel.default.svc.cluster.local
K-Proxy-Request: activator
X-Request-Id: 505ff620-2822-9e7d-8855-53d02a2e36e2
Content-Length: 63
X-B3-Parentspanid: 9e822f378ead293c
X-B3-Spanid: a56ee81909c767e6
----------------------------
``` ```
And as expected it's now been handled by both the first and second Step as And as expected it's now been handled by both the first and second Step as

View File

@ -1,12 +1,12 @@
apiVersion: sources.eventing.knative.dev/v1alpha1 apiVersion: sources.knative.dev/v1alpha1
kind: CronJobSource kind: PingSource
metadata: metadata:
name: cronjob-source name: ping-source
spec: spec:
schedule: "*/2 * * * *" schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}' data: '{"message": "Hello world!"}'
sink: sink:
ref: ref:
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
name: sequence name: sequence

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -1,10 +1,10 @@
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: sequence name: sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:

View File

@ -6,15 +6,14 @@ type: "docs"
--- ---
We are going to create the following logical configuration. We create a We are going to create the following logical configuration. We create a
CronJobSource, feeding events into the Broker, then we create a `Filter` that PingSource, feeding events into the Broker, then we create a `Filter` that
wires those events into a [`Sequence`](../../../sequence.md) consisting of 3 wires those events into a [`Sequence`](../../../flows/sequence.md) consisting of 3
steps. Then we take the end of the Sequence and feed newly minted events back steps. Then we take the end of the Sequence and feed newly minted events back
into the Broker and create another Trigger which will then display those events. into the Broker and create another Trigger which will then display those events.
## Prerequisites ## Prerequisites
For this example, we'll assume you have set up a `Broker` and an For this example, we'll assume you have set up an `InMemoryChannel` as well as Knative Serving (for our functions). The examples
`InMemoryChannel` as well as Knative Serving (for our functions). The examples
use `default` namespace, again, if your broker lives in another Namespace, you use `default` namespace, again, if your broker lives in another Namespace, you
will need to modify the examples to reflect this. will need to modify the examples to reflect this.
@ -28,6 +27,14 @@ The functions used in these examples live in
## Setup ## Setup
### Creating the Broker
The easiest way to create a Broker is to annotate your namespace:
```shell
kubectl label namespace default knative-eventing-injection=enabled
```
### Create the Knative Services ### Create the Knative Services
Change `default` below to create the steps in the Namespace where you have Change `default` below to create the steps in the Namespace where you have
@ -91,13 +98,13 @@ spec.channelTemplate to point to your desired Channel.
Also, change the spec.reply.name to point to your `Broker` Also, change the spec.reply.name to point to your `Broker`
```yaml ```yaml
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: sequence name: sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:
@ -115,7 +122,7 @@ spec:
reply: reply:
ref: ref:
kind: Broker kind: Broker
apiVersion: eventing.knative.dev/v1alpha1 apiVersion: eventing.knative.dev/v1beta1
name: default name: default
``` ```
@ -126,22 +133,22 @@ configured your `Broker`.
kubectl -n default create -f ./sequence.yaml kubectl -n default create -f ./sequence.yaml
``` ```
### Create the CronJobSource targeting the Broker ### Create the PingSource targeting the Broker
This will create a CronJobSource which will send a CloudEvent with {"message": This will create a PingSource which will send a CloudEvent with {"message":
"Hello world!"} as the data payload every 2 minutes. "Hello world!"} as the data payload every 2 minutes.
```yaml ```yaml
apiVersion: sources.eventing.knative.dev/v1alpha1 apiVersion: sources.knative.dev/v1alpha1
kind: CronJobSource kind: PingSource
metadata: metadata:
name: cronjob-source name: ping-source
spec: spec:
schedule: "*/2 * * * *" schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}' data: '{"message": "Hello world!"}'
sink: sink:
ref: ref:
apiVersion: eventing.knative.dev/v1alpha1 apiVersion: eventing.knative.dev/v1beta1
kind: Broker kind: Broker
name: default name: default
``` ```
@ -154,23 +161,23 @@ Change `default` below to create the `Sequence` in the Namespace where you have
configured your `Broker`. configured your `Broker`.
```shell ```shell
kubectl -n default create -f ./cron-source.yaml kubectl -n default create -f ./ping-source.yaml
``` ```
### Create the Trigger targeting the Sequence ### Create the Trigger targeting the Sequence
```yaml ```yaml
apiVersion: eventing.knative.dev/v1alpha1 apiVersion: eventing.knative.dev/v1beta1
kind: Trigger kind: Trigger
metadata: metadata:
name: sequence-trigger name: sequence-trigger
spec: spec:
filter: filter:
attributes: attributes:
type: dev.knative.cronjob.event type: dev.knative.sources.ping
subscriber: subscriber:
ref: ref:
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
name: sequence name: sequence
``` ```
@ -232,16 +239,20 @@ kubectl -n default get pods
Then look at the logs for the event-display pod: Then look at the logs for the event-display pod:
```shell ```shell
kubectl -n default logs --tail=50 -l serving.knative.dev/service=sequence-display -c user-container kubectl -n default logs -l serving.knative.dev/service=sequence-display -c user-container --tail=-1
☁️ cloudevents.Event ☁️ cloudevents.Event
Validation: valid Validation: valid
Context Attributes, Context Attributes,
cloudEventsVersion: 0.1 specversion: 1.0
eventType: samples.http.mod3 type: samples.http.mod3
source: /transformer/2 source: /apis/v1/namespaces/default/pingsources/ping-source
eventID: df52b47e-02fd-45b2-8180-dabb572573f5 id: 159bba01-054a-4ae7-b7be-d4e7c5f773d2
eventTime: 2019-06-18T14:18:42.478140635Z time: 2020-03-03T14:56:00.000652027Z
contentType: application/json datacontenttype: application/json
Extensions,
knativearrivaltime: 2020-03-03T14:56:00.018390608Z
knativehistory: default-kne-trigger-kn-channel.default.svc.cluster.local; sequence-kn-sequence-0-kn-channel.default.svc.cluster.local; sequence-kn-sequence-1-kn-channel.default.svc.cluster.local; sequence-kn-sequence-2-kn-channel.default.svc.cluster.local; default-kne-trigger-kn-channel.default.svc.cluster.local
traceparent: 00-e893412106ff417a90a5695e53ffd9cc-5829ae45a14ed462-00
Data, Data,
{ {
"id": 0, "id": 0,
@ -249,5 +260,5 @@ Data,
} }
``` ```
And you can see that the initial Cron Source message ("Hello World!") has been And you can see that the initial PingSource message `{"Hello World!"}` has been
appended to it by each of the steps in the Sequence. appended to it by each of the steps in the Sequence.

View File

@ -1,12 +0,0 @@
apiVersion: sources.eventing.knative.dev/v1alpha1
kind: CronJobSource
metadata:
name: cronjob-source
spec:
schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}'
sink:
ref:
apiVersion: eventing.knative.dev/v1alpha1
kind: Broker
name: default

View File

@ -6,9 +6,9 @@ spec:
template: template:
spec: spec:
containers: containers:
- image: gcr.io/knative-releases/knative.dev/eventing-sources/cmd/event_display - image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
--- ---
apiVersion: eventing.knative.dev/v1alpha1 apiVersion: eventing.knative.dev/v1beta1
kind: Trigger kind: Trigger
metadata: metadata:
name: display-trigger name: display-trigger

View File

@ -0,0 +1,12 @@
apiVersion: sources.knative.dev/v1alpha1
kind: PingSource
metadata:
name: ping-source
spec:
schedule: "*/2 * * * *"
data: '{"message": "Hello world!"}'
sink:
ref:
apiVersion: eventing.knative.dev/v1beta1
kind: Broker
name: default

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -1,10 +1,10 @@
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
metadata: metadata:
name: sequence name: sequence
spec: spec:
channelTemplate: channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1 apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel kind: InMemoryChannel
steps: steps:
- ref: - ref:
@ -22,5 +22,5 @@ spec:
reply: reply:
ref: ref:
kind: Broker kind: Broker
apiVersion: eventing.knative.dev/v1alpha1 apiVersion: eventing.knative.dev/v1beta1
name: default name: default

View File

@ -33,9 +33,10 @@ spec:
template: template:
spec: spec:
containers: containers:
- image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/appender
env: env:
- name: MESSAGE - name: MESSAGE
value: " - Handled by 2" value: " - Handled by 2"
- name: TYPE
value: "samples.http.mod3"
--- ---

View File

@ -1,4 +1,4 @@
apiVersion: eventing.knative.dev/v1alpha1 apiVersion: eventing.knative.dev/v1beta1
kind: Trigger kind: Trigger
metadata: metadata:
name: sequence-trigger name: sequence-trigger
@ -6,9 +6,9 @@ spec:
broker: default broker: default
filter: filter:
attributes: attributes:
type: dev.knative.cronjob.event type: dev.knative.sources.ping
subscriber: subscriber:
ref: ref:
apiVersion: flows.knative.dev/v1alpha1 apiVersion: flows.knative.dev/v1beta1
kind: Sequence kind: Sequence
name: sequence name: sequence