@@ -43,8 +43,10 @@ import (
4343
4444 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
4545 "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"
4647 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/certs"
4748 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
49+ "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/internal/pruning"
4850 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/labeller"
4951 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/overrides"
5052 "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm/plugins"
@@ -63,6 +65,14 @@ import (
6365 "github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
6466)
6567
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+
6676var (
6777 ErrRequirementsNotMet = errors .New ("requirements were not met" )
6878 ErrCRDOwnerConflict = errors .New ("conflicting CRD owner in namespace" )
@@ -82,7 +92,7 @@ type Operator struct {
8292 client versioned.Interface
8393 lister operatorlister.OperatorLister
8494 protectedCopiedCSVNamespaces map [string ]struct {}
85- copiedCSVLister metadatalister. Lister
95+ copiedCSVLister operatorsv1alpha1listers. ClusterServiceVersionLister
8696 ogQueueSet * queueinformer.ResourceQueueSet
8797 csvQueueSet * queueinformer.ResourceQueueSet
8898 olmConfigQueue workqueue.TypedRateLimitingInterface [types.NamespacedName ]
@@ -294,20 +304,54 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
294304 return nil , err
295305 }
296306
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
298309 // 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 },
308322 },
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 ())
311355 informersByNamespace [namespace ].CopiedCSVInformer = copiedCSVInformer
312356 informersByNamespace [namespace ].CopiedCSVLister = op .copiedCSVLister
313357
0 commit comments