Skip to content

Provide func subscribe for creating Triggers and subscribing to events from the Knative Broker #1956

Open
@matzew

Description

@matzew

Func Subscribe

Feature focused on subscribing to events from a broker, for consumption by the Function.

func subscribe com.foo.bar [--source my-broker]

While the func is an abstraction from direct Knative manifest interaction, the above however would creates a Knative Trigger resource for the given com.foo.bar CloudEvent Type, which will be consumed from the given broker. If the --source is not present, the assumption is to use the default broker.

The func generated Trigger resource for the example above would look like:

apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
  name: my-kn-function-com.foo.bar-trigger
  namespace: default
  ownerReferences:
  - apiVersion: serving.knative.dev/v1
    blockOwnerDeletion: true
    controller: true
    kind: Service
    name: my-kn-function
spec:
  broker: my-broker
  filter:
    attributes:
      type: com.foo.bar
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: my-kn-function

The generated Trigger resource has a ownerReference to the subscribing Service. When the service is being deleted the Trigger will be removed as well, this prevents floating Triggers in the system`.

NOTE: The initial implementation will just focus on the type of the CloudEvent, and will ignore other attributes and custom extensions. This will be added in a later iteration.

Subscribe to all events

Besides subscribing to specific events, it should be possible to subscribe to all events. This is especially nice in the development phase and generally for debugging purposes:

func subscribe --event-all [--source my-broker]

The above invocation would generate a Trigger that has no specific filter, and hence will subscribe to all events, which is especially nice in the development phase, for debugging purposes:

apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
  name: my-kn-function-all-trigger
  namespace: default
  ownerReferences:
  - apiVersion: serving.knative.dev/v1
    blockOwnerDeletion: true
    controller: true
    kind: Service
    name: my-kn-function
spec:
  broker: my-broker
  subscriber:
    ref:
      apiVersion: serving.knative.dev/v1
      kind: Service
      name: my-kn-function

Conflicts with kn CLI

While the func CLI is for a different persona (developers) than the kn CLI (SREs or Admins),it is possible to use the func as a plugin itself on kn.

Creating a Trigger with the kn client goes like:

kn trigger create NAME --sink SINK [options]  

This does create a Trigger resource, for a given sink. While the func would not need the given sink, as the context for the invocation is the function itself, defined in the func.yaml file.

Perhaps the func tool itself (when used as a kn plugin) could leverage the above?

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementlifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions