@@ -31,6 +31,7 @@ import (
3131 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3232 ctrl "sigs.k8s.io/controller-runtime"
3333 "sigs.k8s.io/controller-runtime/pkg/certwatcher"
34+ "sigs.k8s.io/controller-runtime/pkg/client"
3435 "sigs.k8s.io/controller-runtime/pkg/healthz"
3536 "sigs.k8s.io/controller-runtime/pkg/log/zap"
3637 "sigs.k8s.io/controller-runtime/pkg/metrics/filters"
@@ -110,9 +111,15 @@ func (cfg *Config) SetFlags(commandLine *flag.FlagSet) {
110111 "If set, HTTP/2 will be enabled for the metrics and webhook servers" )
111112}
112113
114+ // PluginFactory creates a TranslatorPlugin when provided with the client and scheme.
115+ // This allows plugins to be initialized after the manager is created, giving them access to
116+ // the Kubernetes client and scheme. Plugins should create their own logger.
117+ type PluginFactory func (client.Client , * runtime.Scheme ) transportadapter.TranslatorPlugin
118+
113119type ExtensionConfig struct {
114- // Plugins are translator plugins for extending MCPServer translation behavior
115- Plugins []transportadapter.TranslatorPlugin
120+ // PluginFactories are factories that create translator plugins for extending MCPServer translation behavior.
121+ // These factories are called after the manager is created, allowing plugins to access the client and scheme.
122+ PluginFactories []PluginFactory
116123 // RegisterSchemes is an optional function to register additional API types to the runtime scheme.
117124 // This is called before the manager is created, allowing extensions to add their own CRDs.
118125 RegisterSchemes func (* runtime.Scheme ) error
@@ -265,10 +272,16 @@ func Start(getExtensionConfig GetExtensionConfig) {
265272 os .Exit (1 )
266273 }
267274
275+ var plugins []transportadapter.TranslatorPlugin
276+ for _ , factory := range extensionCfg .PluginFactories {
277+ plugin := factory (mgr .GetClient (), mgr .GetScheme ())
278+ plugins = append (plugins , plugin )
279+ }
280+
268281 if err = (& controller.MCPServerReconciler {
269282 Client : mgr .GetClient (),
270283 Scheme : mgr .GetScheme (),
271- Plugins : extensionCfg . Plugins ,
284+ Plugins : plugins ,
272285 }).SetupWithManager (mgr ); err != nil {
273286 setupLog .Error (err , "unable to create controller" , "controller" , "MCPServer" )
274287 os .Exit (1 )
0 commit comments