EventType auto creation for improved discoverability

Flag name: eventtype-auto-create

Stage: Alpha, disabled by default

Tracking issue: #7044

Persona: Developer

Overview

With the eventtype-auto-creation feature, we have possibliy to auto create EventTypes that are received and ingressed by the Knative Broker and Channel implementations.

For making use of this opt-in feature, we must turn it on in the config-features, by setting the eventtype-auto-create flag to enabled:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: config-features
  5. namespace: knative-eventing
  6. data:
  7. eventtype-auto-create: "enabled"
  8. ...

With this experiemental feature enabled, we get EventTypes on the broker/channel ingress for free, instead of manually creating them as yaml manifests along the application code that talks to the Broker or Channel API.

Example

Create a Broker

To check the feature is working, create a simple broker:

kn CLIApply YAML

  1. kn broker create my-broker
  1. Create a YAML file using the following example:

    1. apiVersion: eventing.knative.dev/v1
    2. kind: Broker
    3. metadata:
    4. namespace: default
    5. name: my-broker
  2. Apply the YAML file by running the command:

    1. kubectl apply -f <filename>.yaml

    Where <filename> is the name of the file you created in the previous step.

Produce Events to the Broker

The auto-creation feature is triggered by processed events. Therefore to verify the functionality we need to send a sample event with desired type. This can be achieved in a severals ways, below are two examples using kn-plugin-event and cURL container in a cluster.

kn eventcURL container

Below is an example that sends an event with the kn CLI, for improved developer productivity. The kn-plugin-event plugin can be installed with Homebrew or downloaded directly from GitHub releases, for more details please refer to plugin instalation steps.

  1. Setup kn event plugin

    1. brew install knative-extensions/kn-plugins/event
  2. Send event

    1. kn event send \
    2. --to Broker:eventing.knative.dev/v1:my-broker\
    3. --type com.corp.integration.warning \
    4. -f message="There might be a problem"

An event can be send via curl in a cluster:

  1. kubectl run curl --image=docker.io/curlimages/curl --rm=true --restart=Never -ti \
  2. -- -X POST -v \
  3. -H "content-type: application/json" \
  4. -H "ce-specversion: 1.0" \
  5. -H "ce-source: my/curl/command" \
  6. -H "ce-type: my.demo.event" \
  7. -H "ce-id: 6cf17c7b-30b1-45a6-80b0-4cf58c92b947" \
  8. -d '{"name":"Knative Demo"}' \
  9. http://broker-ingress.knative-eventing.svc.cluster.local/default/my-broker

This is more complex, as we have to craft the event as part of the curl HTTP POST request.

Event Discovery

After the two produced events, we should be able to have discoverable events in the system, based on the eventtype-auto-creation feature:

  1. k get eventtypes.eventing.knative.dev -A
  2. NAMESPACE NAME TYPE SOURCE SCHEMA BROKER DESCRIPTION READY REASON
  3. default <...> com.corp.integration.warning kn-event/v1.9.0 my-broker True
  4. default <...> my.demo.event my/curl/command my-broker True

Conclusion and Recommendation

With out this feature we would not see the two EventType instances in the system, so we have improved the discoverablilty of events, for consumption. However while this opt-in feature is handy for automatic event creation, we strongly recommend to create the actual EventType manifests for all events that your application deployments produce, as part of your Gitops pipeline, rather than relying on this auto-create feature.