Create a controller

    Example controller:

    1. Generate the components by running the command:

      1. ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
      2. knative.dev/sample-source/pkg/client knative.dev/sample-source/pkg/apis \
      3. "samples:v1alpha1" \
      4. --go-header-file ${REPO_ROOT}/hack/boilerplate/boilerplate.go.txt
    2. Pass the new controller implementation to the sharedmain method:

      1. import (
      2. // The set of controllers this controller process runs.
      3. "knative.dev/sample-source/pkg/reconciler/sample"
      4. // This defines the shared main for injected controllers.
      5. "knative.dev/pkg/injection/sharedmain"
      6. )
      7. func main() {
      8. sharedmain.Main("sample-source-controller", sample.NewController)
      9. }
    3. Define the NewController implementation:

    4. Import the base reconciler from the knative.dev/pkg dependency:

      1. import (
      2. // ...
      3. )
    5. Ensure that the event handlers are being filtered to the correct informers:

      1. deploymentInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
      2. FilterFunc: controller.FilterGroupKind(v1alpha1.Kind("SampleSource")),
      3. Handler: controller.HandleAll(impl.EnqueueControllerOf),
      4. })
      5. sinkBindingInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
      6. FilterFunc: controller.FilterGroupKind(v1alpha1.Kind("SampleSource")),