Sink

A sink is an Addressable resource that acts as a link between the Eventing mesh and an entity or system.

We can connect any source to a sink, such as PingSource and KafkaSink objects:

  1. apiVersion: sources.knative.dev/v1beta1
  2. kind: PingSource
  3. metadata:
  4. name: test-ping-source
  5. spec:
  6. schedule: "*/1 * * * *"
  7. jsonData: '{"message": "Hello world!"}'
  8. sink:
  9. ref:
  10. apiVersion: eventing.knative.dev/v1alpha1
  11. kind: KafkaSink
  12. name: my-kafka-sink

We can connect a Trigger object to a sink, so that we can filter events, before sending them to a sink:

  1. apiVersion: eventing.knative.dev/v1
  2. kind: Trigger
  3. metadata:
  4. name: my-service-trigger
  5. spec:
  6. broker: default
  7. filter:
  8. attributes:
  9. type: dev.knative.foo.bar
  10. myextension: my-extension-value
  11. subscriber:
  12. ref:
  13. apiVersion: eventing.knative.dev/v1alpha1
  14. kind: KafkaSink
  15. name: my-kafka-sink

Setting up a Custom Resource to be used as a sink

To allow a Custom Resource to act as a sink for events, there are two things needed:

1. Make the resource Addressable

To make a Custom Resource Addressable, it needs to contain a status.address.url. More information about Addressable resources.

2. Create an addressable-resolver ClusterRole

An addressable-resolver ClusterRole is needed in order to obtain the necessary RBAC rules for the sink to receive events.

For example, we can create a kafkasinks-addressable-resolver ClusterRole to allow get, list, and watch access to kafkasinks and kafkasinks/status

  1. kind: ClusterRole
  2. apiVersion: rbac.authorization.k8s.io/v1
  3. metadata:
  4. name: kafkasinks-addressable-resolver
  5. labels:
  6. kafka.eventing.knative.dev/release: devel
  7. duck.knative.dev/addressable: "true"
  8. # Do not use this role directly. These rules will be added to the "addressable-resolver" role.
  9. rules:
  10. - apiGroups:
  11. - eventing.knative.dev
  12. resources:
  13. - kafkasinks
  14. - kafkasinks/status
  15. verbs:
  16. - get
  17. - list
  18. - watch

Knative Sinks

NameMaintainerDescription
KafkaSinkKnativeSend events to a Kafka topic
RedisSinkKnativeSend events to a Redis Stream

Table of contents