Skip to content

Commit 0b015f8

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

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pkg/controller/operators/olm/operator.go

+13
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,6 +153,7 @@ 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
@@ -588,6 +594,13 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
588594
OverridesBuilderFunc: overridesBuilderFunc.GetDeploymentInitializer,
589595
}
590596

597+
// initialize plugins
598+
for _, plugin := range op.plugins {
599+
if err := plugin.Init(ctx, config, op); err != nil {
600+
return nil, fmt.Errorf("error initializing plugin: %s", err)
601+
}
602+
}
603+
591604
return op, nil
592605
}
593606

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)