Table of Contents generated with DocToc
The project is used for watching on resources of k8s, when anything changed on the watched resource (add, update, delete), the following action will be taken:
- Send
Cloudevent
to specificurl
- Create k8s event
- Trigger actions
The action
should be pluginable, user could implements what they want, for example: send mail...
It's k8s native and implements by a k8s controller. In this demo, the trigger action will be scale-in and scale-out the operators.
An issue for knative is opened to discuss if Knative has any plan to manage native Kubernetes resources.
go
: The language Tektoncd-pipeline-operator is built ingit
: For source controlkubectl
: For interacting with your kube cluster- operator-sdk: https://github.com/operator-framework/operator-sdk
- ko(https://github.com/google/ko): Build and deploy Go applications on Kubernetes (optional)
The project implements Controller/reconciler
based on operator-sdk
and enhance it to use ko
as build/deploy tool.
The basic idea is wrapping operator deployment into knative serving resource.
- Create CR:
ResourceWatcher
apiVersion: tekton.dev/v1alpha1
kind: ResourceWatcher
metadata:
name: example-resourcewatcher
namespace: tekton-sources
spec:
serviceAccountName: "default"
sink:
apiVersion: serving.knative.dev/v1
kind: Service
name: knative-operator
namespace: default
resources:
- apiVersion: operator.knative.dev/v1alpha1
kind: KnativeEventing
namespaces:
- tekton-sources
means we will watch a specific CR: KnativeEventing
, when creation occurred, a cloudevent
will be send to slink
(this is the wrapper of Operator):
apiVersion: serving.knative.dev/v1
kind: Service
name: knative-operator
namespace: default
then the pod of the KSVC
will be scale from 0 to 1
- When
ResourceWatcher
created, apod
will be created to do the real work. - When target CR is appeared(
KnativeEventing
), - the worker pod will send
cloudenv
toKSVC
(remember it's actually a wrapper of Operator)
Install knative serving first.
- Git clone the repo.
- Deploy
resource-watcher
:
export KO_DOCKER_REPO=docker.io/gyliu
ko apply -f ./deploy
Check if installation succeed by:
[root@symtest11 resource-watcher]# kubectl -n tekton-sources get po
resource-watcher-6bc7c54c65-ctjjq 1/1 Running 0 28h
- Deploy the
operator
ofknative
: knative-operator or
kubectl apply -f ./samples/knative-operator.yaml
For demo, we need delete the deployment
of knative-operator
since we will wrapper the deployment
as a ksvc
.
kubectl delete deployment knative-operator
- Create a
ksvc
who is actually thedeployment
we deleted previously
kubectl create -f ./samples/knative-operator-wrapper.yaml
root@gyliu-dev21:~/go/src/github.com/vincent-pli/resource-watcher# kubectl get service.serving.knative.dev
NAME URL LATESTCREATED LATESTREADY READY REASON
autoscale-go http://autoscale-go-default.apps.gyliu-cap.cp.fyre.ibm.com autoscale-go-00001 autoscale-go-00001 True
knative-operator http://knative-operator-default.apps.gyliu-cap.cp.fyre.ibm.com knative-operator-00001 False RevisionMissing
Note: we modify the original deployment
:
- Add an extra
container
to supply acontainer port
forknative serving
to proxy the request. - Delete original
container port
: 9090 which is for metrics collect, since the 9090 is a internal port forknative
- Modify the
valueFrom
in theenv
defination to static string.
The ksvc
's pod will disppear afterr 60 second by default.
- Watching
knative-operator
'sKnativeEventing
:
kubectl apply -f ./samples/KnativeEventing_resourcewatcher_cr.yaml
Then check this:
[root@symtest11 resource-watcher]# kubectl -n tekton-sources get po
NAME READY STATUS RESTARTS AGE
example-resourcewatcher-deploymenthgcfg-6fb66479bb-wgbbd 1/1 Running 0 11h
resource-watcher-6bc7c54c65-ctjjq 1/1 Running 0 28h
- Create a
KnativeEventing
:
kubectl create -f ./samples/eventing.yaml -n knative-eventing
Then you could see the ksvc
(a wrapper knative-operator
)'s pod will start up and then the knative-eventing
will be installed.