|
7 | 7 | "strings"
|
8 | 8 | "time"
|
9 | 9 |
|
| 10 | + "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/plugins" |
10 | 11 | "github.com/sirupsen/logrus"
|
11 | 12 | admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
|
12 | 13 | corev1 "k8s.io/api/core/v1"
|
|
61 | 62 | ErrAPIServiceOwnerConflict = errors.New("unable to adopt APIService")
|
62 | 63 | )
|
63 | 64 |
|
| 65 | +// this unexported operator plugin slice provides an entrypoint for |
| 66 | +// downstream to inject its own plugins to augment the controller behavior |
| 67 | +var operatorPlugInFactoryFuncs []plugins.OperatorPlugInFactoryFunc |
| 68 | + |
64 | 69 | type Operator struct {
|
65 | 70 | queueinformer.Operator
|
66 | 71 |
|
@@ -91,6 +96,7 @@ type Operator struct {
|
91 | 96 | clientAttenuator *scoped.ClientAttenuator
|
92 | 97 | serviceAccountQuerier *scoped.UserDefinedServiceAccountQuerier
|
93 | 98 | clientFactory clients.Factory
|
| 99 | + plugins []plugins.OperatorPlugin |
94 | 100 | }
|
95 | 101 |
|
96 | 102 | func NewOperator(ctx context.Context, options ...OperatorOption) (*Operator, error) {
|
@@ -588,6 +594,31 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
|
588 | 594 | OverridesBuilderFunc: overridesBuilderFunc.GetDeploymentInitializer,
|
589 | 595 | }
|
590 | 596 |
|
| 597 | + // initialize plugins |
| 598 | + for _, makePlugIn := range operatorPlugInFactoryFuncs { |
| 599 | + plugin, err := makePlugIn(ctx, config, op) |
| 600 | + if err != nil { |
| 601 | + return nil, fmt.Errorf("error creating plugin: %s", err) |
| 602 | + } |
| 603 | + op.plugins = append(op.plugins, plugin) |
| 604 | + } |
| 605 | + |
| 606 | + if len(operatorPlugInFactoryFuncs) > 0 { |
| 607 | + go func() { |
| 608 | + // block until operator is done |
| 609 | + <-op.Done() |
| 610 | + |
| 611 | + // shutdown plug-ins |
| 612 | + for _, plugin := range op.plugins { |
| 613 | + if err := plugin.Shutdown(); err != nil { |
| 614 | + if op.logger != nil { |
| 615 | + op.logger.Warnf("error shutting down plug-in: %s", err) |
| 616 | + } |
| 617 | + } |
| 618 | + } |
| 619 | + }() |
| 620 | + } |
| 621 | + |
591 | 622 | return op, nil
|
592 | 623 | }
|
593 | 624 |
|
|
0 commit comments