This repo uses MetaController to automatically search for all CustomResourceDefinition
s that have the label AutoContainerSource=Is-Controlling-This-CRD
and annotation AutoContainerSourceImage=<DockerImage>
. It will then reconcile all instances of those CRDs, by creating a ContainerSource
for each. It uses the image found in the CRD's annotation. Any CRD spec
fields directly understood by the ContainerSource
will be passed as the ContainerSource
's spec
(i.e. serviceAccountName
and sink
). All other CRD spec
fields are sent as environment variables on the ContainerSource
(whose value is the JSON string representing their value in the CRD spec
).
For example:
If I had the following CRD:
apiVersion: sources.eventing.knative.dev/v1alpha1
kind: K8sEventSource
metadata:
name: k8seventsource-sample
namespace: default
spec:
namespace: default
serviceAccountName: k8seventsource
sink:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: k8ssource
randomField: 123
randomOtherField:
baz:
- 1
- hello
- 2
- world
foo: bar
qux:
hi: there
Would generate the following ContainerSource
:
apiVersion: sources.eventing.knative.dev/v1alpha1
kind: ContainerSource
metadata:
name: k8seventsource-sample-ea3211d5-0312-11e9-8193-42010a80019e
namespace: default
spec:
env:
- name: namespace
value: '"default"'
- name: randomField
value: "123"
- name: randomOtherField
value: '{"baz": [1, "hello", 2, "world"], "foo": "bar", "qux": {"hi": "there"}}'
image: gcr.io/harwayne2/cmd-bf183bbaaf47d0b67277bbc91fa2b42b@sha256:4f91ac63e5cc4f45a0d806be04468110d92ad3c2c71bdd265df321b50ad0f55b
serviceAccountName: k8seventsource
sink:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: k8ssource
This runs two distinct Kubernetes Deployment
s and Service
s.
-
auto-container-crd-metacontroller
- Watches all
CustomResourceDefinition
s for those with the appropriate label and annotation. If found, create a MetaControllerCompositeController
for that CRD.- A
DecoratorController
is what causesauto-container-crd-metacontroller
to watch CRDs.
- A
- Watches all
-
auto-container-cr-reifier-metacontroller
- Creates a
ContainerSource
for each instantiation of a CRD with the appropriate label and annotation. Syncs the image and arguments down as well as the status up. CompositeController
s generated byauto-container-crd-metacontroller
point at thisDeployment
.
- Creates a
-
Install Knative and Knative Eventing.
-
Install Metacontroller.
- I happen to be using 0.3.0.
-
Set your docker user as an environment variable.
export DOCKER_USER=foobar
-
Install the two
Deployments
../apply-crd-decorator.sh ./apply-cr-reifier.sh
See k8s-event-source.