@@ -24,6 +24,8 @@ import (
24
24
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
25
25
"k8s.io/client-go/informers"
26
26
k8sscheme "k8s.io/client-go/kubernetes/scheme"
27
+ "k8s.io/client-go/metadata/metadatainformer"
28
+ "k8s.io/client-go/metadata/metadatalister"
27
29
"k8s.io/client-go/tools/cache"
28
30
"k8s.io/client-go/tools/record"
29
31
"k8s.io/client-go/util/workqueue"
@@ -35,12 +37,10 @@ import (
35
37
"github.com/operator-framework/api/pkg/operators/v1alpha1"
36
38
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
37
39
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/informers/externalversions"
38
- operatorsv1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
39
40
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/certs"
40
41
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
41
- "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/internal/pruning"
42
42
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/overrides"
43
- resolver "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
43
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
44
44
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/clients"
45
45
csvutility "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/csv"
46
46
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/event"
@@ -75,7 +75,7 @@ type Operator struct {
75
75
client versioned.Interface
76
76
lister operatorlister.OperatorLister
77
77
protectedCopiedCSVNamespaces map [string ]struct {}
78
- copiedCSVLister operatorsv1alpha1listers. ClusterServiceVersionLister
78
+ copiedCSVLister metadatalister. Lister
79
79
ogQueueSet * queueinformer.ResourceQueueSet
80
80
csvQueueSet * queueinformer.ResourceQueueSet
81
81
olmConfigQueue workqueue.RateLimitingInterface
@@ -127,6 +127,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
127
127
if err := k8sscheme .AddToScheme (scheme ); err != nil {
128
128
return nil , err
129
129
}
130
+ if err := metav1 .AddMetaToScheme (scheme ); err != nil {
131
+ return nil , err
132
+ }
130
133
131
134
op := & Operator {
132
135
Operator : queueOperator ,
@@ -208,44 +211,20 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
208
211
return nil , err
209
212
}
210
213
211
- // A separate informer solely for CSV copies. Fields
212
- // are pruned from local copies of the objects managed
214
+ // A separate informer solely for CSV copies. Object metadata requests are used
213
215
// by this informer in order to reduce cached size.
214
- copiedCSVInformer := cache .NewSharedIndexInformer (
215
- pruning .NewListerWatcher (
216
- op .client ,
217
- namespace ,
218
- func (opts * metav1.ListOptions ) {
219
- opts .LabelSelector = v1alpha1 .CopiedLabelKey
220
- },
221
- pruning .PrunerFunc (func (csv * v1alpha1.ClusterServiceVersion ) {
222
- nonstatus , status := copyableCSVHash (csv )
223
- * csv = v1alpha1.ClusterServiceVersion {
224
- TypeMeta : csv .TypeMeta ,
225
- ObjectMeta : csv .ObjectMeta ,
226
- Status : v1alpha1.ClusterServiceVersionStatus {
227
- Phase : csv .Status .Phase ,
228
- Reason : csv .Status .Reason ,
229
- },
230
- }
231
- if csv .Annotations == nil {
232
- csv .Annotations = make (map [string ]string , 2 )
233
- }
234
- // These annotation keys are
235
- // intentionally invalid -- all writes
236
- // to copied CSVs are regenerated from
237
- // the corresponding non-copied CSV,
238
- // so it should never be transmitted
239
- // back to the API server.
240
- csv .Annotations ["$copyhash-nonstatus" ] = nonstatus
241
- csv .Annotations ["$copyhash-status" ] = status
242
- }),
243
- ),
244
- & v1alpha1.ClusterServiceVersion {},
216
+ gvr := v1alpha1 .SchemeGroupVersion .WithResource ("clusterserviceversions" )
217
+ copiedCSVInformer := metadatainformer .NewFilteredMetadataInformer (
218
+ config .metadataClient ,
219
+ gvr ,
220
+ namespace ,
245
221
config .resyncPeriod (),
246
222
cache.Indexers {cache .NamespaceIndex : cache .MetaNamespaceIndexFunc },
247
- )
248
- op .copiedCSVLister = operatorsv1alpha1listers .NewClusterServiceVersionLister (copiedCSVInformer .GetIndexer ())
223
+ func (options * metav1.ListOptions ) {
224
+ options .LabelSelector = v1alpha1 .CopiedLabelKey
225
+ },
226
+ ).Informer ()
227
+ op .copiedCSVLister = metadatalister .New (copiedCSVInformer .GetIndexer (), gvr )
249
228
250
229
// Register separate queue for gcing copied csvs
251
230
copiedCSVGCQueue := workqueue .NewNamedRateLimitingQueue (workqueue .DefaultControllerRateLimiter (), fmt .Sprintf ("%s/csv-gc" , namespace ))
@@ -1195,17 +1174,16 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
1195
1174
}
1196
1175
}
1197
1176
1198
- func (a * Operator ) removeDanglingChildCSVs (csv * v1alpha1. ClusterServiceVersion ) error {
1177
+ func (a * Operator ) removeDanglingChildCSVs (csv * metav1. PartialObjectMetadata ) error {
1199
1178
logger := a .logger .WithFields (logrus.Fields {
1200
1179
"id" : queueinformer .NewLoopID (),
1201
1180
"csv" : csv .GetName (),
1202
1181
"namespace" : csv .GetNamespace (),
1203
- "phase" : csv .Status .Phase ,
1204
1182
"labels" : csv .GetLabels (),
1205
1183
"annotations" : csv .GetAnnotations (),
1206
1184
})
1207
1185
1208
- if ! csv .IsCopied () {
1186
+ if ! v1alpha1 .IsCopied (csv ) {
1209
1187
logger .Warning ("removeDanglingChild called on a parent. this is a no-op but should be avoided." )
1210
1188
return nil
1211
1189
}
@@ -1244,7 +1222,7 @@ func (a *Operator) removeDanglingChildCSVs(csv *v1alpha1.ClusterServiceVersion)
1244
1222
return nil
1245
1223
}
1246
1224
1247
- func (a * Operator ) deleteChild (csv * v1alpha1. ClusterServiceVersion , logger * logrus.Entry ) error {
1225
+ func (a * Operator ) deleteChild (csv * metav1. PartialObjectMetadata , logger * logrus.Entry ) error {
1248
1226
logger .Debug ("gcing csv" )
1249
1227
return a .client .OperatorsV1alpha1 ().ClusterServiceVersions (csv .GetNamespace ()).Delete (context .TODO (), csv .GetName (), metav1.DeleteOptions {})
1250
1228
}
@@ -1683,12 +1661,12 @@ func (a *Operator) createCSVCopyingDisabledEvent(csv *v1alpha1.ClusterServiceVer
1683
1661
}
1684
1662
1685
1663
func (a * Operator ) syncGcCsv (obj interface {}) (syncError error ) {
1686
- clusterServiceVersion , ok := obj .(* v1alpha1. ClusterServiceVersion )
1664
+ clusterServiceVersion , ok := obj .(* metav1. PartialObjectMetadata )
1687
1665
if ! ok {
1688
1666
a .logger .Debugf ("wrong type: %#v" , obj )
1689
1667
return fmt .Errorf ("casting ClusterServiceVersion failed" )
1690
1668
}
1691
- if clusterServiceVersion .IsCopied () {
1669
+ if v1alpha1 .IsCopied (clusterServiceVersion ) {
1692
1670
syncError = a .removeDanglingChildCSVs (clusterServiceVersion )
1693
1671
return
1694
1672
}
0 commit comments