Skip to content

Commit ea79ffa

Browse files
committed
Add olm operator plug-in framework
Signed-off-by: perdasilva <[email protected]>
1 parent 665c25b commit ea79ffa

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pkg/controller/operators/olm/operator.go

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ var (
6161
ErrAPIServiceOwnerConflict = errors.New("unable to adopt APIService")
6262
)
6363

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+
6468
type Operator struct {
6569
queueinformer.Operator
6670

@@ -91,6 +95,7 @@ type Operator struct {
9195
clientAttenuator *scoped.ClientAttenuator
9296
serviceAccountQuerier *scoped.UserDefinedServiceAccountQuerier
9397
clientFactory clients.Factory
98+
plugins []OperatorPlugin
9499
}
95100

96101
func NewOperator(ctx context.Context, options ...OperatorOption) (*Operator, error) {
@@ -148,10 +153,12 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
148153
serviceAccountQuerier: scoped.NewUserDefinedServiceAccountQuerier(config.logger, config.externalClient),
149154
clientFactory: clients.NewFactory(config.restConfig),
150155
protectedCopiedCSVNamespaces: config.protectedCopiedCSVNamespaces,
156+
plugins: operatorPlugIns,
151157
}
152158

153159
// Set up syncing for namespace-scoped resources
154160
k8sSyncer := queueinformer.LegacySyncHandler(op.syncObject).ToSyncerWithDelete(op.handleDeletion)
161+
155162
for _, namespace := range config.watchedNamespaces {
156163
// Wire CSVs
157164
csvInformer := externalversions.NewSharedInformerFactoryWithOptions(
@@ -588,6 +595,13 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
588595
OverridesBuilderFunc: overridesBuilderFunc.GetDeploymentInitializer,
589596
}
590597

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+
591605
return op, nil
592606
}
593607

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package olm
2+
3+
import "context"
4+
5+
// OperatorPlugin provides a simple interface
6+
// that can be used to extend the olm operator's functionality
7+
type OperatorPlugin interface {
8+
Init(ctx context.Context, config *operatorConfig, operator *Operator) error
9+
}

0 commit comments

Comments
 (0)