|
61 | 61 | ErrAPIServiceOwnerConflict = errors.New("unable to adopt APIService")
|
62 | 62 | )
|
63 | 63 |
|
| 64 | +// this unexported operator plugin slice provides and entrypoint for |
| 65 | +// downstream to inject its own plugins to augment the controller behavior |
| 66 | +var operatorPlugIns []OperatorPlugin |
| 67 | + |
64 | 68 | type Operator struct {
|
65 | 69 | queueinformer.Operator
|
66 | 70 |
|
@@ -91,6 +95,7 @@ type Operator struct {
|
91 | 95 | clientAttenuator *scoped.ClientAttenuator
|
92 | 96 | serviceAccountQuerier *scoped.UserDefinedServiceAccountQuerier
|
93 | 97 | clientFactory clients.Factory
|
| 98 | + plugins []OperatorPlugin |
94 | 99 | }
|
95 | 100 |
|
96 | 101 | func NewOperator(ctx context.Context, options ...OperatorOption) (*Operator, error) {
|
@@ -148,10 +153,12 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
|
148 | 153 | serviceAccountQuerier: scoped.NewUserDefinedServiceAccountQuerier(config.logger, config.externalClient),
|
149 | 154 | clientFactory: clients.NewFactory(config.restConfig),
|
150 | 155 | protectedCopiedCSVNamespaces: config.protectedCopiedCSVNamespaces,
|
| 156 | + plugins: operatorPlugIns, |
151 | 157 | }
|
152 | 158 |
|
153 | 159 | // Set up syncing for namespace-scoped resources
|
154 | 160 | k8sSyncer := queueinformer.LegacySyncHandler(op.syncObject).ToSyncerWithDelete(op.handleDeletion)
|
| 161 | + |
155 | 162 | for _, namespace := range config.watchedNamespaces {
|
156 | 163 | // Wire CSVs
|
157 | 164 | csvInformer := externalversions.NewSharedInformerFactoryWithOptions(
|
@@ -588,6 +595,13 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
|
588 | 595 | OverridesBuilderFunc: overridesBuilderFunc.GetDeploymentInitializer,
|
589 | 596 | }
|
590 | 597 |
|
| 598 | + // initialize plugins |
| 599 | + for _, plugin := range op.plugins { |
| 600 | + if err := plugin.Init(ctx, config, op); err != nil { |
| 601 | + return nil, fmt.Errorf("error initializing plugin: %s", err) |
| 602 | + } |
| 603 | + } |
| 604 | + |
591 | 605 | return op, nil
|
592 | 606 | }
|
593 | 607 |
|
|
0 commit comments