@@ -43,8 +43,10 @@ import (
43
43
44
44
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
45
45
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/informers/externalversions"
46
+ operatorsv1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
46
47
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/certs"
47
48
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
49
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/internal/pruning"
48
50
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/labeller"
49
51
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/overrides"
50
52
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/plugins"
@@ -63,6 +65,14 @@ import (
63
65
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
64
66
)
65
67
68
+ const (
69
+ // These annotation keys are intentionally invalid -- all writes
70
+ // to copied CSVs are regenerated from the corresponding non-copied CSV,
71
+ // so it should never be transmitted back to the API server.
72
+ copyCSVStatusHash = "$copyhash-status"
73
+ copyCSVSpecHash = "$copyhash-spec"
74
+ )
75
+
66
76
var (
67
77
ErrRequirementsNotMet = errors .New ("requirements were not met" )
68
78
ErrCRDOwnerConflict = errors .New ("conflicting CRD owner in namespace" )
@@ -82,7 +92,7 @@ type Operator struct {
82
92
client versioned.Interface
83
93
lister operatorlister.OperatorLister
84
94
protectedCopiedCSVNamespaces map [string ]struct {}
85
- copiedCSVLister metadatalister. Lister
95
+ copiedCSVLister operatorsv1alpha1listers. ClusterServiceVersionLister
86
96
ogQueueSet * queueinformer.ResourceQueueSet
87
97
csvQueueSet * queueinformer.ResourceQueueSet
88
98
olmConfigQueue workqueue.TypedRateLimitingInterface [types.NamespacedName ]
@@ -294,20 +304,54 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
294
304
return nil , err
295
305
}
296
306
297
- // A separate informer solely for CSV copies. Object metadata requests are used
307
+ // A separate informer solely for CSV copies. Fields
308
+ // are pruned from local copies of the objects managed
298
309
// by this informer in order to reduce cached size.
299
- gvr := v1alpha1 .SchemeGroupVersion .WithResource ("clusterserviceversions" )
300
- copiedCSVInformer := metadatainformer .NewFilteredMetadataInformer (
301
- config .metadataClient ,
302
- gvr ,
303
- namespace ,
304
- config .resyncPeriod (),
305
- cache.Indexers {cache .NamespaceIndex : cache .MetaNamespaceIndexFunc },
306
- func (options * metav1.ListOptions ) {
307
- options .LabelSelector = v1alpha1 .CopiedLabelKey
310
+ copiedCSVInformer := cache .NewSharedIndexInformerWithOptions (
311
+ pruning .NewListerWatcher (
312
+ op .client ,
313
+ namespace ,
314
+ func (opts * metav1.ListOptions ) {
315
+ opts .LabelSelector = v1alpha1 .CopiedLabelKey
316
+ },
317
+ ),
318
+ & v1alpha1.ClusterServiceVersion {},
319
+ cache.SharedIndexInformerOptions {
320
+ ResyncPeriod : config .resyncPeriod (),
321
+ Indexers : cache.Indexers {cache .NamespaceIndex : cache .MetaNamespaceIndexFunc },
308
322
},
309
- ).Informer ()
310
- op .copiedCSVLister = metadatalister .New (copiedCSVInformer .GetIndexer (), gvr )
323
+ )
324
+
325
+ // Transform the copied CSV to be just the Metadata
326
+ // However, because we have the full copied CSV, we can calculate
327
+ // a hash over the full CSV to store as an annotation
328
+ copiedCSVTransformFunc := func (i interface {}) (interface {}, error ) {
329
+ if csv , ok := i .(* v1alpha1.ClusterServiceVersion ); ok {
330
+ specHash , statusHash , err := copyableCSVHash (csv )
331
+ if err != nil {
332
+ return nil , err
333
+ }
334
+ * csv = v1alpha1.ClusterServiceVersion {
335
+ TypeMeta : csv .TypeMeta ,
336
+ ObjectMeta : csv .ObjectMeta ,
337
+ Spec : v1alpha1.ClusterServiceVersionSpec {},
338
+ Status : v1alpha1.ClusterServiceVersionStatus {},
339
+ }
340
+ if csv .Annotations == nil {
341
+ csv .Annotations = make (map [string ]string , 2 )
342
+ }
343
+ // fake CSV hashes for tracking purposes only
344
+ csv .Annotations [copyCSVSpecHash ] = specHash
345
+ csv .Annotations [copyCSVStatusHash ] = statusHash
346
+ return csv , nil
347
+ }
348
+ return nil , fmt .Errorf ("Unable to convert input to CSV" )
349
+ }
350
+
351
+ if err := copiedCSVInformer .SetTransform (copiedCSVTransformFunc ); err != nil {
352
+ return nil , err
353
+ }
354
+ op .copiedCSVLister = operatorsv1alpha1listers .NewClusterServiceVersionLister (copiedCSVInformer .GetIndexer ())
311
355
informersByNamespace [namespace ].CopiedCSVInformer = copiedCSVInformer
312
356
informersByNamespace [namespace ].CopiedCSVLister = op .copiedCSVLister
313
357
0 commit comments