@@ -7,11 +7,11 @@ import (
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"
13
14
rbacv1 "k8s.io/api/rbac/v1"
14
- apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
15
15
extinf "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions"
16
16
apierrors "k8s.io/apimachinery/pkg/api/errors"
17
17
"k8s.io/apimachinery/pkg/api/meta"
61
61
ErrAPIServiceOwnerConflict = errors .New ("unable to adopt APIService" )
62
62
)
63
63
64
+ // this unexported operator plugin slice provides an entrypoint for
65
+ // downstream to inject its own plugins to augment the controller behavior
66
+ var operatorPlugInFactoryFuncs []plugins.OperatorPlugInFactoryFunc
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 []plugins.OperatorPlugin
94
99
}
95
100
96
101
func NewOperator (ctx context.Context , options ... OperatorOption ) (* Operator , error ) {
@@ -588,6 +593,31 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
588
593
OverridesBuilderFunc : overridesBuilderFunc .GetDeploymentInitializer ,
589
594
}
590
595
596
+ // initialize plugins
597
+ for _ , makePlugIn := range operatorPlugInFactoryFuncs {
598
+ plugin , err := makePlugIn (ctx , config , op )
599
+ if err != nil {
600
+ return nil , fmt .Errorf ("error creating plugin: %s" , err )
601
+ }
602
+ op .plugins = append (op .plugins , plugin )
603
+ }
604
+
605
+ if len (operatorPlugInFactoryFuncs ) > 0 {
606
+ go func () {
607
+ // block until operator is done
608
+ <- op .Done ()
609
+
610
+ // shutdown plug-ins
611
+ for _ , plugin := range op .plugins {
612
+ if err := plugin .Shutdown (); err != nil {
613
+ if op .logger != nil {
614
+ op .logger .Warnf ("error shutting down plug-in: %s" , err )
615
+ }
616
+ }
617
+ }
618
+ }()
619
+ }
620
+
591
621
return op , nil
592
622
}
593
623
@@ -1122,46 +1152,6 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
1122
1152
logger .WithError (err ).Warnf ("failed to requeue gc event: %v" , webhook )
1123
1153
}
1124
1154
}
1125
-
1126
- // Conversion webhooks are defined within a CRD.
1127
- // In an effort to prevent customer dataloss, OLM does not delete CRDs associated with a CSV when it is deleted.
1128
- // Deleting a CSV that introduced a conversion webhook removes the deployment that serviced the conversion webhook calls.
1129
- // If a conversion webhook is defined and the service isn't available, all requests against the CR associated with the CRD will fail.
1130
- // This ultimately breaks kubernetes garbage collection and prevents OLM from reinstalling the CSV as CR validation against the new CRD's
1131
- // openapiv3 schema fails.
1132
- // As such, when a CSV is deleted OLM will check if it is being replaced. If the CSV is not being replaced, OLM will remove the conversion
1133
- // webhook from the CRD definition.
1134
- csvs , err := a .lister .OperatorsV1alpha1 ().ClusterServiceVersionLister ().ClusterServiceVersions (clusterServiceVersion .GetNamespace ()).List (labels .Everything ())
1135
- if err != nil {
1136
- logger .Errorf ("error listing csvs: %v\n " , err )
1137
- }
1138
- for _ , csv := range csvs {
1139
- if csv .Spec .Replaces == clusterServiceVersion .GetName () {
1140
- return
1141
- }
1142
- }
1143
-
1144
- for _ , desc := range clusterServiceVersion .Spec .WebhookDefinitions {
1145
- if desc .Type != v1alpha1 .ConversionWebhook || len (desc .ConversionCRDs ) == 0 {
1146
- continue
1147
- }
1148
-
1149
- for i , crdName := range desc .ConversionCRDs {
1150
- crd , err := a .lister .APIExtensionsV1 ().CustomResourceDefinitionLister ().Get (crdName )
1151
- if err != nil {
1152
- logger .Errorf ("error getting CRD %v which was defined in CSVs spec.WebhookDefinition[%d]: %v\n " , crdName , i , err )
1153
- continue
1154
- }
1155
-
1156
- copy := crd .DeepCopy ()
1157
- copy .Spec .Conversion .Strategy = apiextensionsv1 .NoneConverter
1158
- copy .Spec .Conversion .Webhook = nil
1159
-
1160
- if _ , err = a .opClient .ApiextensionsInterface ().ApiextensionsV1 ().CustomResourceDefinitions ().Update (context .TODO (), copy , metav1.UpdateOptions {}); err != nil {
1161
- logger .Errorf ("error updating conversion strategy for CRD %v: %v\n " , crdName , err )
1162
- }
1163
- }
1164
- }
1165
1155
}
1166
1156
1167
1157
func (a * Operator ) removeDanglingChildCSVs (csv * v1alpha1.ClusterServiceVersion ) error {
0 commit comments