Skip to content

Commit 9881f3e

Browse files
authored
Merge pull request #20783 from abrennan89/sinkbinding
Added details of SinkBinding for Serverless
2 parents d25183d + 9d33c33 commit 9881f3e

File tree

4 files changed

+313
-0
lines changed

4 files changed

+313
-0
lines changed

_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,8 @@ Topics:
16531653
### File: serverless-kn-source
16541654
### - Name: Using ApiServerSource
16551655
### File: serverless-apiserversource
1656+
### - Name: Using SinkBinding
1657+
### File: serverless-sinkbinding
16561658
### Triggers
16571659
### - Name: Using triggers with Knative Eventing
16581660
### File: serverless-kn-trigger
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Module included in the following assemblies:
2+
//
3+
// serverless/knstive_eventing/serverless-sinkbinding.adoc
4+
5+
[id="serverless-sinkbinding-kn_{context}"]
6+
= Using SinkBinding with the Knative CLI (`kn`)
7+
8+
This guide describes the steps required to create, manage, and delete a SinkBinding instance using `kn` commands.
9+
10+
.Prerequisites
11+
12+
* You have Knative Serving and Eventing installed.
13+
* You have the `kn` CLI installed.
14+
15+
.Procedure
16+
17+
. To check that SinkBinding is set up correctly, create a Knative event display service, or event sink, that dumps incoming messages to its log:
18+
+
19+
----
20+
$ kn service create event-display --image quay.io/openshift-knative/knative-eventing-sources-event-display:v0.13.2
21+
----
22+
23+
. Create a SinkBinding that directs events to the service:
24+
+
25+
----
26+
$ kn source binding create bind-heartbeat --subject Job:batch/v1:app=heartbeat-cron --sink svc:event-display
27+
----
28+
29+
. Create a CronJob.
30+
.. Create a file named `heartbeats-cronjob.yaml` and copy the following sample code into it:
31+
+
32+
----
33+
apiVersion: batch/v1beta1
34+
kind: CronJob
35+
metadata:
36+
name: heartbeat-cron
37+
spec:
38+
spec:
39+
# Run every minute
40+
schedule: "* * * * *"
41+
jobTemplate:
42+
metadata:
43+
labels:
44+
app: heartbeat-cron
45+
spec:
46+
template:
47+
spec:
48+
restartPolicy: Never
49+
containers:
50+
- name: single-heartbeat
51+
image: quay.io/openshift-knative/knative-eventing-sources-heartbeats:v0.13.2
52+
args:
53+
- --period=1
54+
env:
55+
- name: ONE_SHOT
56+
value: "true"
57+
- name: POD_NAME
58+
valueFrom:
59+
fieldRef:
60+
fieldPath: metadata.name
61+
- name: POD_NAMESPACE
62+
valueFrom:
63+
fieldRef:
64+
fieldPath: metadata.namespace
65+
----
66+
.. After you have created the `heartbeats-cronjob.yaml` file, apply it by entering:
67+
+
68+
----
69+
$ oc apply --filename heartbeats-cronjob.yaml
70+
----
71+
72+
. Check that the controller is mapped correctly by entering the following command and inspecting the output:
73+
+
74+
----
75+
$ kn source binding describe bind-heartbeat
76+
----
77+
+
78+
The output should be similar to:
79+
+
80+
----
81+
Name: bind-heartbeat
82+
Namespace: demo-2
83+
Annotations: sources.knative.dev/creator=minikube-user, sources.knative.dev/lastModifier=minikub ...
84+
Age: 2m
85+
Subject:
86+
Resource: job (batch/v1)
87+
Selector:
88+
app: heartbeat-cron
89+
Sink:
90+
Name: event-display
91+
Resource: Service (serving.knative.dev/v1)
92+
93+
Conditions:
94+
OK TYPE AGE REASON
95+
++ Ready 2m
96+
----
97+
98+
.Verification steps
99+
100+
You can verify that the Kubernetes events were sent to the Knative event sink by looking at the message dumper function logs.
101+
102+
You can view the message dumper function logs by entering:
103+
----
104+
$ oc get pods
105+
$ oc logs $(oc get pod -o name | grep event-display) -c user-container
106+
----
107+
108+
The logs should contain lines similar to the following:
109+
----
110+
☁️ cloudevents.Event
111+
Validation: valid
112+
Context Attributes,
113+
specversion: 1.0
114+
type: dev.knative.eventing.samples.heartbeat
115+
source: https://knative.dev/eventing-contrib/cmd/heartbeats/#event-test/mypod
116+
id: 2b72d7bf-c38f-4a98-a433-608fbcdd2596
117+
time: 2019-10-18T15:23:20.809775386Z
118+
contenttype: application/json
119+
Extensions,
120+
beats: true
121+
heart: yes
122+
the: 42
123+
Data,
124+
{
125+
"id": 1,
126+
"label": ""
127+
}
128+
----
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Module included in the following assemblies:
2+
//
3+
// serverless/knstive_eventing/serverless-sinkbinding.adoc
4+
5+
[id="serverless-sinkbinding-yaml_{context}"]
6+
= Using SinkBinding with the YAML method
7+
8+
This guide describes the steps required to create, manage, and delete a SinkBinding instance using YAML files.
9+
10+
.Prerequisites
11+
12+
* You have Knative Serving and Eventing installed.
13+
14+
.Procedure
15+
16+
. To check that SinkBinding is set up correctly, create a Knative event display service, or event sink, that dumps incoming messages to its log.
17+
.. Copy the following sample YAML into a file named `service.yaml`:
18+
+
19+
----
20+
apiVersion: serving.knative.dev/v1
21+
kind: Service
22+
metadata:
23+
name: event-display
24+
spec:
25+
template:
26+
spec:
27+
containers:
28+
- image: quay.io/openshift-knative/knative-eventing-sources-event-display:v0.13.2
29+
----
30+
.. After you have created the `service.yaml` file, apply it by entering:
31+
+
32+
----
33+
$ oc apply --filename service.yaml
34+
----
35+
36+
. Create a SinkBinding that directs events to the service.
37+
.. Create a file named `sinkbinding.yaml` and copy the following sample code into it:
38+
+
39+
----
40+
apiVersion: sources.knative.dev/v1alpha1
41+
kind: SinkBinding
42+
metadata:
43+
name: bind-heartbeat
44+
spec:
45+
subject:
46+
apiVersion: batch/v1
47+
kind: Job <1>
48+
selector:
49+
matchLabels:
50+
app: heartbeat-cron
51+
52+
sink:
53+
ref:
54+
apiVersion: serving.knative.dev/v1
55+
kind: Service
56+
name: event-display
57+
----
58+
+
59+
<1> In this example, any Job with the label `app: heartbeat-cron` will be bound to the event sink.
60+
.. After you have created the `sinkbinding.yaml` file, apply it by entering:
61+
+
62+
----
63+
$ oc apply --filename sinkbinding.yaml
64+
----
65+
66+
. Create a CronJob.
67+
.. Create a file named `heartbeats-cronjob.yaml` and copy the following sample code into it:
68+
+
69+
----
70+
apiVersion: batch/v1beta1
71+
kind: CronJob
72+
metadata:
73+
name: heartbeat-cron
74+
spec:
75+
spec:
76+
# Run every minute
77+
schedule: "* * * * *"
78+
jobTemplate:
79+
metadata:
80+
labels:
81+
app: heartbeat-cron
82+
spec:
83+
template:
84+
spec:
85+
restartPolicy: Never
86+
containers:
87+
- name: single-heartbeat
88+
image: quay.io/openshift-knative/knative-eventing-sources-heartbeats:v0.13.2
89+
args:
90+
- --period=1
91+
env:
92+
- name: ONE_SHOT
93+
value: "true"
94+
- name: POD_NAME
95+
valueFrom:
96+
fieldRef:
97+
fieldPath: metadata.name
98+
- name: POD_NAMESPACE
99+
valueFrom:
100+
fieldRef:
101+
fieldPath: metadata.namespace
102+
----
103+
.. After you have created the `heartbeats-cronjob.yaml` file, apply it by entering:
104+
+
105+
----
106+
$ oc apply --filename heartbeats-cronjob.yaml
107+
----
108+
109+
. Check that the controller is mapped correctly by entering the following command and inspecting the output:
110+
+
111+
----
112+
$ oc get sinkbindings.sources.knative.dev bind-heartbeat -oyaml
113+
----
114+
+
115+
The output should be similar to:
116+
+
117+
----
118+
spec:
119+
sink:
120+
ref:
121+
apiVersion: serving.knative.dev/v1
122+
kind: Service
123+
name: event-display
124+
namespace: default
125+
subject:
126+
apiVersion: batch/v1
127+
kind: Job
128+
namespace: default
129+
selector:
130+
matchLabels:
131+
app: heartbeat-cron
132+
----
133+
134+
.Verification steps
135+
136+
You can verify that the Kubernetes events were sent to the Knative event sink by looking at the message dumper function logs.
137+
138+
You can view the message dumper function logs by entering:
139+
----
140+
$ oc get pods
141+
$ oc logs $(oc get pod -o name | grep event-display) -c user-container
142+
----
143+
144+
The logs should contain lines similar to the following:
145+
----
146+
☁️ cloudevents.Event
147+
Validation: valid
148+
Context Attributes,
149+
specversion: 1.0
150+
type: dev.knative.eventing.samples.heartbeat
151+
source: https://knative.dev/eventing-contrib/cmd/heartbeats/#event-test/mypod
152+
id: 2b72d7bf-c38f-4a98-a433-608fbcdd2596
153+
time: 2019-10-18T15:23:20.809775386Z
154+
contenttype: application/json
155+
Extensions,
156+
beats: true
157+
heart: yes
158+
the: 42
159+
Data,
160+
{
161+
"id": 1,
162+
"label": ""
163+
}
164+
----
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
include::modules/serverless-document-attributes.adoc[]
2+
[id="serverless-sinkbinding"]
3+
= Using SinkBinding
4+
include::modules/common-attributes.adoc[]
5+
:context: serverless-sinkbinding
6+
7+
toc::[]
8+
9+
SinkBinding is used to connect event producers, or _event sources_, to an event consumer, or _event sink_, for example, a Knative service or application.
10+
11+
[NOTE]
12+
====
13+
Both of the following procedures require you to create YAML files.
14+
15+
If you change the names of the YAML files from those used in the examples, you must ensure that you also update the corresponding CLI commands.
16+
====
17+
18+
include::modules/serverless-sinkbinding-kn.adoc[leveloffset=+1]
19+
include::modules/serverless-sinkbinding-yaml.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)