Create a controller
Example controller:
Generate the components by running the command:
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
knative.dev/sample-source/pkg/client knative.dev/sample-source/pkg/apis \
"samples:v1alpha1" \
--go-header-file ${REPO_ROOT}/hack/boilerplate/boilerplate.go.txt
Pass the new controller implementation to the
sharedmain
method:import (
// The set of controllers this controller process runs.
"knative.dev/sample-source/pkg/reconciler/sample"
// This defines the shared main for injected controllers.
"knative.dev/pkg/injection/sharedmain"
)
func main() {
sharedmain.Main("sample-source-controller", sample.NewController)
}
Define the
NewController
implementation:Import the base reconciler from the
knative.dev/pkg
dependency:import (
// ...
)
Ensure that the event handlers are being filtered to the correct informers:
-
deploymentInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: controller.FilterGroupKind(v1alpha1.Kind("SampleSource")),
Handler: controller.HandleAll(impl.EnqueueControllerOf),
})
sinkBindingInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: controller.FilterGroupKind(v1alpha1.Kind("SampleSource")),