Skip to content

Commit c050da8

Browse files
Ville Aikasknative-prow-robot
authored andcommitted
Add docs / samples for Sequence (#1481)
* sequence with broker * add sequence -> sequence sample * sequence wired to event display * terminal sequence * first two examples moved to new v1beta1 services + cascading changes * fix sequence2sequence to use v1beta services / default ns * fix broker example to use v1beta1 service + default ns * Address PR feedback * add a pointer to vaikas-google/transformer sample * update transformer image refs to latest * address PR feedback * move overview before prerequisites, add link to main sequence page
1 parent 80ab0ac commit c050da8

26 files changed

+1462
-0
lines changed
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
---
2+
title: "Sequence Wired to event-display"
3+
weight: 20
4+
type: "docs"
5+
---
6+
7+
# Using Sequences in series
8+
9+
## Overview
10+
11+
We are going to create the following logical configuration. We create a CronJobSource,
12+
feeding events to a (`Sequence`)[../../../sequence.md], then taking the output of that `Sequence` and
13+
displaying the resulting output.
14+
15+
![Logical Configuration](./sequence-reply-to-event-display.png)
16+
17+
## Prerequisites
18+
19+
For this example, we'll assume you have set up an `InMemoryChannel`
20+
as well as Knative Serving (for our functions). The examples use `default`
21+
namespace, again, if you want to deploy to another Namespace, you will need
22+
to modify the examples to reflect this.
23+
24+
If you want to use different type of `Channel`, you will have to modify the
25+
`Sequence.Spec.ChannelTemplate` to create the appropriate Channel resources.
26+
27+
28+
## Setup
29+
30+
### Create the Knative Services
31+
32+
Change `default` below to create the steps in the Namespace where you want resources
33+
created.
34+
35+
```yaml
36+
apiVersion: serving.knative.dev/v1beta1
37+
kind: Service
38+
metadata:
39+
name: first
40+
spec:
41+
template:
42+
spec:
43+
containers:
44+
- image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700
45+
env:
46+
- name: STEP
47+
value: "0"
48+
49+
---
50+
apiVersion: serving.knative.dev/v1beta1
51+
kind: Service
52+
metadata:
53+
name: second
54+
spec:
55+
template:
56+
spec:
57+
containers:
58+
- image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700
59+
env:
60+
- name: STEP
61+
value: "1"
62+
---
63+
apiVersion: serving.knative.dev/v1beta1
64+
kind: Service
65+
metadata:
66+
name: third
67+
spec:
68+
template:
69+
spec:
70+
containers:
71+
- image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700
72+
env:
73+
- name: STEP
74+
value: "2"
75+
---
76+
```
77+
78+
79+
```shell
80+
kubectl -n default create -f ./steps.yaml
81+
```
82+
83+
### Create the Sequence
84+
85+
The `sequence.yaml` file contains the specifications for creating the Sequence. If you are using a different type of Channel, you need to change the
86+
spec.channelTemplate to point to your desired Channel.
87+
88+
```yaml
89+
apiVersion: messaging.knative.dev/v1alpha1
90+
kind: Sequence
91+
metadata:
92+
name: sequence
93+
spec:
94+
channelTemplate:
95+
apiVersion: messaging.knative.dev/v1alpha1
96+
kind: InMemoryChannel
97+
steps:
98+
- ref:
99+
apiVersion: serving.knative.dev/v1beta1
100+
kind: Service
101+
name: first
102+
- ref:
103+
apiVersion: serving.knative.dev/v1beta1
104+
kind: Service
105+
name: second
106+
- ref:
107+
apiVersion: serving.knative.dev/v1beta1
108+
kind: Service
109+
name: third
110+
reply:
111+
kind: Service
112+
apiVersion: serving.knative.dev/v1beta1
113+
name: event-display
114+
```
115+
116+
Change `default` below to create the `Sequence` in the Namespace where you want the
117+
resources to be created.
118+
```shell
119+
kubectl -n default create -f ./sequence.yaml
120+
```
121+
122+
123+
### Create the Service displaying the events created by Sequence
124+
125+
```yaml
126+
apiVersion: serving.knative.dev/v1beta1
127+
kind: Service
128+
metadata:
129+
name: event-display
130+
spec:
131+
template:
132+
spec:
133+
containers:
134+
- image: gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/event_display
135+
```
136+
137+
Change `default` below to create the `Sequence` in the Namespace where you want your resources
138+
to be created.
139+
140+
```shell
141+
kubectl -n default create -f ./event-display.yaml
142+
```
143+
144+
### Create the CronJobSource targeting the Sequence
145+
146+
This will create a CronJobSource which will send a CloudEvent with {"message": "Hello world!"} as
147+
the data payload every 2 minutes.
148+
149+
```yaml
150+
apiVersion: sources.eventing.knative.dev/v1alpha1
151+
kind: CronJobSource
152+
metadata:
153+
name: cronjob-source
154+
spec:
155+
schedule: "*/2 * * * *"
156+
data: '{"message": "Hello world!"}'
157+
sink:
158+
apiVersion: messaging.knative.dev/v1alpha1
159+
kind: Sequence
160+
name: sequence
161+
```
162+
163+
```shell
164+
kubectl -n default create -f ./cron-source.yaml
165+
```
166+
167+
### Inspecting the results
168+
169+
You can now see the final output by inspecting the logs of the event-display pods.
170+
171+
```shell
172+
kubectl -n default get pods
173+
```
174+
175+
Then look at the logs for the event-display pod:
176+
177+
178+
```shell
179+
kubectl -n default logs -l serving.knative.dev/service=event-display -c user-container
180+
☁️ cloudevents.Event
181+
Validation: valid
182+
Context Attributes,
183+
cloudEventsVersion: 0.1
184+
eventType: samples.http.mod3
185+
source: /transformer/2
186+
eventID: df52b47e-02fd-45b2-8180-dabb572573f5
187+
eventTime: 2019-06-18T14:18:42.478140635Z
188+
contentType: application/json
189+
Data,
190+
{
191+
"id": 0,
192+
"message": "Hello world! - Handled by 0 - Handled by 1 - Handled by 2"
193+
}
194+
```
195+
196+
And you can see that the initial Cron Source message ("Hello World!") has been appended to it by each
197+
of the steps in the Sequence.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: sources.eventing.knative.dev/v1alpha1
2+
kind: CronJobSource
3+
metadata:
4+
name: cronjob-source
5+
spec:
6+
schedule: "*/2 * * * *"
7+
data: '{"message": "Hello world!"}'
8+
sink:
9+
apiVersion: messaging.knative.dev/v1alpha1
10+
kind: Sequence
11+
name: sequence
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: serving.knative.dev/v1beta1
2+
kind: Service
3+
metadata:
4+
name: event-display
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- image: gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/event_display
11.9 KB
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: messaging.knative.dev/v1alpha1
2+
kind: Sequence
3+
metadata:
4+
name: sequence
5+
spec:
6+
channelTemplate:
7+
apiVersion: messaging.knative.dev/v1alpha1
8+
kind: InMemoryChannel
9+
steps:
10+
- ref:
11+
apiVersion: serving.knative.dev/v1beta1
12+
kind: Service
13+
name: first
14+
- ref:
15+
apiVersion: serving.knative.dev/v1beta1
16+
kind: Service
17+
name: second
18+
- ref:
19+
apiVersion: serving.knative.dev/v1beta1
20+
kind: Service
21+
name: third
22+
reply:
23+
kind: Service
24+
apiVersion: serving.knative.dev/v1beta1
25+
name: event-display
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: serving.knative.dev/v1alpha1
2+
kind: Service
3+
metadata:
4+
name: first
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700
10+
env:
11+
- name: STEP
12+
value: "0"
13+
14+
---
15+
apiVersion: serving.knative.dev/v1alpha1
16+
kind: Service
17+
metadata:
18+
name: second
19+
spec:
20+
template:
21+
spec:
22+
containers:
23+
- image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700
24+
env:
25+
- name: STEP
26+
value: "1"
27+
---
28+
apiVersion: serving.knative.dev/v1alpha1
29+
kind: Service
30+
metadata:
31+
name: third
32+
spec:
33+
template:
34+
spec:
35+
containers:
36+
- image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700
37+
env:
38+
- name: STEP
39+
value: "2"
40+
---

0 commit comments

Comments
 (0)