-
Notifications
You must be signed in to change notification settings - Fork 552
OLM operator support for downstream plug-ins #2843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 1 commit into
operator-framework:master
from
perdasilva:csv_event_handling
Aug 29, 2022
+106
−10
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/plugins" | ||
"github.com/sirupsen/logrus" | ||
admissionregistrationv1 "k8s.io/api/admissionregistration/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
|
@@ -61,6 +62,10 @@ var ( | |
ErrAPIServiceOwnerConflict = errors.New("unable to adopt APIService") | ||
) | ||
|
||
// this unexported operator plugin slice provides an entrypoint for | ||
// downstream to inject its own plugins to augment the controller behavior | ||
var operatorPlugInFactoryFuncs []plugins.OperatorPlugInFactoryFunc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using factory functions instead of the instantiated plug-in objects themselves. This guarantees that each instance of the operator gets their own instance of the plug-ins |
||
|
||
type Operator struct { | ||
queueinformer.Operator | ||
|
||
|
@@ -91,6 +96,7 @@ type Operator struct { | |
clientAttenuator *scoped.ClientAttenuator | ||
serviceAccountQuerier *scoped.UserDefinedServiceAccountQuerier | ||
clientFactory clients.Factory | ||
plugins []plugins.OperatorPlugin | ||
} | ||
|
||
func NewOperator(ctx context.Context, options ...OperatorOption) (*Operator, error) { | ||
|
@@ -588,6 +594,31 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat | |
OverridesBuilderFunc: overridesBuilderFunc.GetDeploymentInitializer, | ||
} | ||
|
||
// initialize plugins | ||
for _, makePlugIn := range operatorPlugInFactoryFuncs { | ||
plugin, err := makePlugIn(ctx, config, op) | ||
if err != nil { | ||
return nil, fmt.Errorf("error creating plugin: %s", err) | ||
} | ||
op.plugins = append(op.plugins, plugin) | ||
} | ||
|
||
if len(operatorPlugInFactoryFuncs) > 0 { | ||
go func() { | ||
// block until operator is done | ||
<-op.Done() | ||
|
||
// shutdown plug-ins | ||
for _, plugin := range op.plugins { | ||
if err := plugin.Shutdown(); err != nil { | ||
if op.logger != nil { | ||
op.logger.Warnf("error shutting down plug-in: %s", err) | ||
} | ||
} | ||
} | ||
}() | ||
} | ||
|
||
return op, nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package plugins | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned" | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient" | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// HostOperator is an extensible and observable operator that hosts the plug-in, i.e. which the plug-in is extending | ||
type HostOperator interface { | ||
queueinformer.ObservableOperator | ||
queueinformer.ExtensibleOperator | ||
} | ||
|
||
// OperatorConfig gives access to required configuration from the host operator | ||
type OperatorConfig interface { | ||
OperatorClient() operatorclient.ClientInterface | ||
ExternalClient() versioned.Interface | ||
ResyncPeriod() func() time.Duration | ||
WatchedNamespaces() []string | ||
Logger() *logrus.Logger | ||
} | ||
|
||
// OperatorPlugin provides a simple interface | ||
// that can be used to extend the olm operator's functionality | ||
type OperatorPlugin interface { | ||
// Shutdown is called once the host operator is done | ||
// to give the plug-in a change to clean up resources if necessary | ||
Shutdown() error | ||
} | ||
|
||
// OperatorPlugInFactoryFunc factory function that returns a new instance of a plug-in | ||
type OperatorPlugInFactoryFunc func(ctx context.Context, config OperatorConfig, hostOperator HostOperator) (OperatorPlugin, error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These chances go in conjunction with the OperatorConfig client interface on the plug-in package. This way the plug-in can have access to some of the configuration information