Documentation ¶
Overview ¶
Package injection defines the mechanisms through which clients, informers and shared informer factories are injected into a shared controller binary implementation.
There are two primary contexts where the usage of the injection package is interesting. The first is in the context of implementations of `controller.Reconciler` being wrapped in a `*controller.Impl`:
import ( // Simply linking this triggers the injection of the informer, which links // the factory triggering its injection, and which links the client, // triggering its injection. All you need to know is that it works :) deployinformer "knative.dev/pkg/injection/informers/kubeinformers/appsv1/deployment" "knative.dev/pkg/injection" ) func NewController(ctx context.Context) *controller.Impl { deploymentInformer := deployinformer.Get(ctx) // Pass deploymentInformer.Lister() to Reconciler ... // Set up events on deploymentInformer.Informer() ... }
Then in `package main` the entire controller process can be set up via:
package main import ( // The set of controllers this controller process runs. // Linking these will register their transitive dependencies, after // which the shared main can set up the rest. "github.com/knative/foo/pkg/reconciler/matt" "github.com/knative/foo/pkg/reconciler/scott" "github.com/knative/foo/pkg/reconciler/ville" "github.com/knative/foo/pkg/reconciler/dave" // This defines the shared main for injected controllers. "knative.dev/pkg/injection/sharedmain" ) func main() { sharedmain.Main("mycomponent", // We pass in the list of controllers to construct, and that's it! // If we forget to add this, go will complain about the unused import. matt.NewController, scott.NewController, ville.NewController, dave.NewController, ) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientInjector ¶
ClientInjector holds the type of a callback that attaches a particular client type to a context.
type ControllerConstructor ¶
type InformerFactoryInjector ¶
InformerFactoryInjector holds the type of a callback that attaches a particular factory type to a context.
type InformerInjector ¶
InformerInjector holds the type of a callback that attaches a particular informer type to a context.
type Interface ¶
type Interface interface { // RegisterClient registers a new injector callback for associating // a new client with a context. RegisterClient(ClientInjector) // GetClients fetches all of the registered client injectors. GetClients() []ClientInjector // RegisterInformerFactory registers a new injector callback for associating // a new informer factory with a context. RegisterInformerFactory(InformerFactoryInjector) // GetInformerFactories fetches all of the registered informer factory injectors. GetInformerFactories() []InformerFactoryInjector // RegisterInformer registers a new injector callback for associating // a new informer with a context. RegisterInformer(InformerInjector) // GetInformers fetches all of the registered informer injectors. GetInformers() []InformerInjector // SetupInformers runs all of the injectors against a context, starting with // the clients and the given rest.Config. The resulting context is returned // along with a list of the .Informer() for each of the injected informers, // which is suitable for passing to controller.StartInformers(). // This does not setup or start any controllers. SetupInformers(context.Context, *rest.Config) (context.Context, []controller.Informer) }
Interface is the interface for interacting with injection implementations, such as our Default and Fake below.
var ( // Default is the injection interface with which informers should register // to make themselves available to the controller process when reconcilers // are being run for real. Default Interface = &impl{} // Fake is the injection interface with which informers should register // to make themselves available to the controller process when it is being // unit tested. Fake Interface = &impl{} )