Skip to content

Instantly share code, notes, and snippets.

@evankanderson
Last active February 15, 2019 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evankanderson/c5a5ac3183d5ca94a0030f6adf6a40f0 to your computer and use it in GitHub Desktop.
Save evankanderson/c5a5ac3183d5ca94a0030f6adf6a40f0 to your computer and use it in GitHub Desktop.
Auto-creation of black-box sources
  1. This is very high-level and half baked.
  2. This is intended to suggest one way that black-box sources could be auto-created in specific circumstances from a declaration of interest in events.
  3. This assumes a model somewhat similar to Broker and Trigger (called Broker and Rules here) with the following additions:
    1. The Rule has a filter expression which matches more than event types. I've used CEL here.
    2. There is a process which propagates "upstream" (i.e. from consumer to origin) the set of filters currently listening.
  4. We use an annotation, eventing.knative.dev/filter, as a way to copy filters from the Rules upstream through the components towards the event origin. Using an annotation allows non-filtering entities (such as Channel or Subscription) to propagate their filters upstream, even though they don't perform any filtering of their own.
  5. This assumes that the user has also made github-enabled secrets available to the default service account, and that the githubsource CR defaults to using the default service account. (This means a one-time setup to enable GitHub, and then githubsources will be auto-generated as rules requesting them are called for.

Read in order:

# This is the rule where I listen for GitHub events for a repo or organization.
apiVersion: eventing.knative.dev/v1alpha1
kind: Rule
metadata:
name: knative-sockpuppet
annotations: # Filled in by propagation agent, not written by user.
eventing.knative.dev/filter: |
['type = "" && source.startsWith("https://github.com/knative/eventing/")']
spec:
filter:
expression: 'type = "github.pull_request.create" && source.startsWith("https://github.com/knative/eventing/")'
target:
ref:
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: sockpuppet
# Internal implementation of the ingress filtering function for the broker
apiVersion: internal.eventing.knative.dev/v1alpha1
kind: BrokerRouter
metadata:
name: default
annotations:
eventing.knative.dev/filter: \ # List of all downstream Rule filters, copied from annotations on downstreams and merged.
['....',
'type = "github.pull_request.create" && source.startsWith("https://github.com/knative/eventing/")',
'....',
]
spec:
....
filter: | # Auto-filled by the filter propagator from the eventing.knative.dev/filter annotation using '||' of conditions.
....
("github.pull_request.create" && source.startsWith("https://github.com/knative/eventing/"))
....
# GitHub CRD has annotations that indicate that you can create a CR to fulfil
# type = github.* and source ~= https://github.com/([^/]+)
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustemResourceDefinition
metadata:
name: githubsources.sources.knative.dev
labels:
eventing.knative.dev/source: "true"
annotations:
eventing.knative.dev/sourceFulfilment: | # I hate naming
type_prefix: "github" # If type prefix matches this regex
type_property_list: "spec.eventTypes" # Put type into this field
source_prefix: "https://github.com/([^/]+)" # If source prefix matches this regex
source_property: "spec.ownerAndRepository" # Put source into this field
spec:
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment