Knative servinng events controller
defines a controller for knative serving
resource and listens for Knative Service events and generates corresponding CloudEvents
taking the tektoncd controller as a reference implementation.
The following roughly defines the controller components:
- We register 2 Informers:
- A
ServingV1/Service
reconciler - Embed the CloudEvents SDK client.
- We also register a CloudEvents 'receiver' which listens at port
8080
.
The following sequence diagram shows the interaction between the components
- Setup a test cluster using KIND with
make cluster
- Install Knative with
make install-knative
- Install CRDs with
make install-crds
- Run the controller with
make run-controllers
Now create a dummy Knative service
echo "apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: hello
spec:
template:
spec:
containers:
- image: gcr.io/google-samples/hello-app:1.0
" | kubectl apply -f -
We will see the corresponding events received by the controller and subsequently the emitted cloudevent
received:
Context Attributes,
specversion: 1.0
type: cd.service.deployed.v1 # event of type deployed
source: default/hello
id: 1fc4b160-e859-4177-8847-b85c19fdbc18
time: 2022-01-20T16:56:39.010077Z
On updating the previously created ksvc
object, we should see a corresponding event of type upgraded
- - image: gcr.io/google-samples/hello-app:1.0
+ - image: gcr.io/google-samples/hello-app:2.0
This generates the upgraded event and should be reflected in the event as well:
Context Attributes,
specversion: 1.0
type: cd.service.upgraded.v1 # event of type upgraded
source: default/hello
id: 23225ed1-3dcc-4772-a60d-72ab57bb1ba3
time: 2022-01-20T17:16:00.253051Z
- Clearing the previous
ksvc
object
kubectl delete ksvc hello
- Trigger a cloud event of type
created
(cd.service.created.v1
) with the following command:
go run cmd/cloudevent/produce.go
This should create a ksvc
object in the cluster
note that the event used here (
cd.service.created.v1
) is not yet defined by the CloudEvents sdk and is just hardcoded for demo purposes.
Check for the created Knative service by running:
kubectl get ksvc
If you are interested in contributing, see CONTRIBUTING.md and DEVELOPMENT.md.