|
| 1 | +[id="serverless-sinkbinding-odc_{context}"] |
| 2 | += Creating a sink binding using the Developer perspective |
| 3 | + |
| 4 | +You can create and verify a basic sink binding from the {product-title} web console. |
| 5 | + |
| 6 | +.Prerequisites |
| 7 | + |
| 8 | +To create a sink binding using the *Developer* perspective, ensure that: |
| 9 | + |
| 10 | +* The {ServerlessOperatorName}, Knative Serving, and Knative Eventing are installed on your {product-title} cluster. |
| 11 | +* You have logged in to the web console. |
| 12 | +* You are in the *Developer* perspective. |
| 13 | +* You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in {product-title}. |
| 14 | + |
| 15 | +.Procedure |
| 16 | + |
| 17 | +. Create a Knative service to use as a sink: |
| 18 | +.. In the *Developer* perspective, navigate to *+Add* -> *YAML*. |
| 19 | +.. Copy the example YAML: |
| 20 | ++ |
| 21 | +[source,yaml] |
| 22 | +---- |
| 23 | +apiVersion: serving.knative.dev/v1 |
| 24 | +kind: Service |
| 25 | +metadata: |
| 26 | + name: event-display |
| 27 | +spec: |
| 28 | + template: |
| 29 | + spec: |
| 30 | + containers: |
| 31 | + - image: quay.io/openshift-knative/knative-eventing-sources-event-display:latest |
| 32 | +---- |
| 33 | +.. Click *Create*. |
| 34 | + |
| 35 | +. Create a `CronJob` resource that is used as an event source and sends an event every minute. |
| 36 | +.. In the *Developer* perspective, navigate to *+Add* -> *YAML*. |
| 37 | +.. Copy the example YAML: |
| 38 | ++ |
| 39 | +[source,yaml] |
| 40 | +---- |
| 41 | +apiVersion: batch/v1 |
| 42 | +kind: CronJob |
| 43 | +metadata: |
| 44 | + name: heartbeat-cron |
| 45 | +spec: |
| 46 | + # Run every minute |
| 47 | + schedule: "*/1 * * * *" |
| 48 | + jobTemplate: |
| 49 | + metadata: |
| 50 | + labels: |
| 51 | + app: heartbeat-cron |
| 52 | + bindings.knative.dev/include: true <1> |
| 53 | + spec: |
| 54 | + template: |
| 55 | + spec: |
| 56 | + restartPolicy: Never |
| 57 | + containers: |
| 58 | + - name: single-heartbeat |
| 59 | + image: quay.io/openshift-knative/heartbeats |
| 60 | + args: |
| 61 | + - --period=1 |
| 62 | + env: |
| 63 | + - name: ONE_SHOT |
| 64 | + value: "true" |
| 65 | + - name: POD_NAME |
| 66 | + valueFrom: |
| 67 | + fieldRef: |
| 68 | + fieldPath: metadata.name |
| 69 | + - name: POD_NAMESPACE |
| 70 | + valueFrom: |
| 71 | + fieldRef: |
| 72 | + fieldPath: metadata.namespace |
| 73 | +---- |
| 74 | +<1> Ensure that you include the `bindings.knative.dev/include: true` label. The default namespace selection behavior of {ServerlessProductName} uses inclusion mode. |
| 75 | +.. Click *Create*. |
| 76 | + |
| 77 | +. Create a sink binding in the same namespace as the service created in the previous step, or any other sink that you want to send events to. |
| 78 | +.. In the *Developer* perspective, navigate to *+Add* -> *Event Source*. The *Event Sources* page is displayed. |
| 79 | +.. Optional: If you have multiple providers for your event sources, select the required provider from the *Providers* list to filter the available event sources from the provider. |
| 80 | +.. Select *Sink Binding* and then click *Create Event Source*. The *Create Event Source* page is displayed. |
| 81 | +.. In the *apiVersion* field enter `batch/v1`. |
| 82 | +.. In the *Kind* field enter `Job`. |
| 83 | ++ |
| 84 | +[NOTE] |
| 85 | +==== |
| 86 | +The `CronJob` kind is not supported directly by {ServerlessProductName} sink binding, so the *Kind* field must target the `Job` objects created by the cron job, rather than the cron job object itself. |
| 87 | +==== |
| 88 | +.. Select a *Sink*. This can be either a *Resource* or a *URI*. In this example, the `event-display` service created in the previous step is used as the *Resource* sink. |
| 89 | +.. In the *Match labels* section: |
| 90 | +... Enter `app` in the *Name* field. |
| 91 | +... Enter `heartbeat-cron` in the *Value* field. |
| 92 | ++ |
| 93 | +[NOTE] |
| 94 | +==== |
| 95 | +The label selector is required when using cron jobs with sink binding, rather than the resource name. This is because jobs created by a cron job do not have a predictable name, and contain a randomly generated string in their name. For example, `hearthbeat-cron-1cc23f`. |
| 96 | +==== |
| 97 | +.. Click *Create*. |
| 98 | + |
| 99 | +.Verification |
| 100 | + |
| 101 | +You can verify that the sink binding, sink, and cron job have been created and are working correctly by viewing the *Topology* page and pod logs. |
| 102 | + |
| 103 | +. In the *Developer* perspective, navigate to *Topology*. |
| 104 | +. View the sink binding, sink, and heartbeats cron job. |
| 105 | ++ |
| 106 | +image::verify-sinkbinding-odc.png[View the sink binding and service in the Topology view] |
| 107 | +. Observe that successful jobs are being registered by the cron job once the sink binding is added. This means that the sink binding is successfully reconfiguring the jobs created by the cron job. |
| 108 | +. Browse the logs of the the `event-display` service pod to see events produced by the heartbeats cron job. |
0 commit comments