Knative Eventing Sugar Controller

Knative Eventing Sugar Controller will react to special labels and annotations to produce or control eventing resources in a cluster or namespace. This allows cluster operators and developers to focus on creating fewer resources, and the underlying eventing infrastructure is created on-demand, and cleaned up when no longer needed.

Installing

The following command installs the Eventing Sugar Controller:

  1. kubectl apply --filename https://github.com/knative/eventing/releases/download/v0.22.0/eventing-sugar-controller.yaml

Automatic Broker Creation

One way to create a Broker is to manually apply a resource to a cluster using the default settings:

  1. kubectl create -f - <<EOF
  2. apiVersion: eventing.knative.dev/v1
  3. kind: Broker
  4. metadata:
  5. name: default
  6. namespace: default
  7. EOF

There might be cases where automated Broker creation is desirable, such as on namespace creation, or on Trigger creation. The Sugar controller enables those use-cases:

  • When a Namespace is labeled with eventing.knative.dev/injection=enabled, the sugar controller will create a default Broker named “default” in that namespace.
  • When a Trigger is annotated with eventing.knative.dev/injection=enabled, the controller will create a Broker named by that Trigger in the Trigger’s Namespace.

When a Broker is deleted and the above labels or annotations are in-use, the Sugar Controller will automatically recreate a default Broker.

Namespace Examples

Creating a “default” Broker when creating a Namespace:

  1. kubectl apply -f - <<EOF
  2. apiVersion: v1
  3. kind: Namespace
  4. metadata:
  5. name: example
  6. labels:
  7. eventing.knative.dev/injection: enabled
  8. EOF

To automatically create a Broker after a namespace exists, label the Namespace:

  1. kubectl label namespace default eventing.knative.dev/injection=enabled

If the Broker named “default” already exists in the Namespace, the Sugar Controller will do nothing.

Trigger Examples

Create a Broker named by a Trigger (spec.broker) in the Trigger’s Namespace:

  1. kubectl apply -f - << EOF
  2. apiVersion: eventing.knative.dev/v1
  3. kind: Trigger
  4. metadata:
  5. name: hello-sugar
  6. namespace: hello
  7. annotations:
  8. eventing.knative.dev/injection: enabled
  9. spec:
  10. broker: sugar
  11. subscriber:
  12. ref:
  13. apiVersion: v1
  14. kind: Service
  15. name: event-display
  16. EOF

Note: If the named Broker already exists, the Sugar controller will do nothing, and the Trigger will not own the existing Broker.

This will make a Broker called “sugar” in the Namespace “hello”, and attempt to send events to the “event-display” service.

If the Broker of the given name already exists in the Namespace, the Sugar Controller will do nothing.

Table of contents