@@ -307,7 +307,6 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
307307 // A separate informer solely for CSV copies. Fields
308308 // are pruned from local copies of the objects managed
309309 // by this informer in order to reduce cached size.
310-
311310 copiedCSVInformer := cache .NewSharedIndexInformerWithOptions (
312311 listerwatcher .NewListerWatcher (
313312 op .client ,
@@ -328,6 +327,7 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
328327 // a hash over the full CSV to store as an annotation
329328 copiedCSVTransformFunc := func (i interface {}) (interface {}, error ) {
330329 if csv , ok := i .(* v1alpha1.ClusterServiceVersion ); ok {
330+ config .logger .WithField ("name" , fmt .Sprintf ("%s/%s" , csv .Namespace , csv .Name )).Info ("Transforming copied CSV" )
331331 specHash , statusHash , err := copyableCSVHash (csv )
332332 if err != nil {
333333 return nil , err
@@ -356,6 +356,28 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
356356 informersByNamespace [namespace ].CopiedCSVInformer = copiedCSVInformer
357357 informersByNamespace [namespace ].CopiedCSVLister = op .copiedCSVLister
358358
359+ // Register separate queue for reverting copied csvs
360+ copiedCSVRevertQueue := workqueue .NewTypedRateLimitingQueueWithConfig [types.NamespacedName ](
361+ workqueue .DefaultTypedControllerRateLimiter [types.NamespacedName ](),
362+ workqueue.TypedRateLimitingQueueConfig [types.NamespacedName ]{
363+ Name : fmt .Sprintf ("%s/csv-revert" , namespace ),
364+ })
365+ op .copiedCSVGCQueueSet .Set (namespace , copiedCSVRevertQueue )
366+ copiedCSVRevertQueueInformer , err := queueinformer .NewQueueInformer (
367+ ctx ,
368+ queueinformer .WithInformer (copiedCSVInformer ),
369+ queueinformer .WithLogger (op .logger ),
370+ queueinformer .WithQueue (copiedCSVRevertQueue ),
371+ queueinformer .WithIndexer (copiedCSVInformer .GetIndexer ()),
372+ queueinformer .WithSyncer (queueinformer .LegacySyncHandler (op .syncRevertCsv ).ToSyncer ()),
373+ )
374+ if err != nil {
375+ return nil , err
376+ }
377+ if err := op .RegisterQueueInformer (copiedCSVRevertQueueInformer ); err != nil {
378+ return nil , err
379+ }
380+
359381 // Register separate queue for gcing copied csvs
360382 copiedCSVGCQueue := workqueue .NewTypedRateLimitingQueueWithConfig [types.NamespacedName ](
361383 workqueue .DefaultTypedControllerRateLimiter [types.NamespacedName ](),
@@ -1723,6 +1745,8 @@ func (a *Operator) syncCopyCSV(obj interface{}) (syncError error) {
17231745 return fmt .Errorf ("casting ClusterServiceVersion failed" )
17241746 }
17251747
1748+ a .logger .WithField ("name" , fmt .Sprintf ("%s/%s" , clusterServiceVersion .Namespace , clusterServiceVersion .Name )).Info ("syncCopyCSV" )
1749+
17261750 olmConfig , err := a .client .OperatorsV1 ().OLMConfigs ().Get (context .TODO (), "cluster" , metav1.GetOptions {})
17271751 if err != nil && ! apierrors .IsNotFound (err ) {
17281752 return err
@@ -1750,9 +1774,13 @@ func (a *Operator) syncCopyCSV(obj interface{}) (syncError error) {
17501774 return
17511775 }
17521776
1753- logger .WithFields (logrus.Fields {
1754- "targetNamespaces" : strings .Join (operatorGroup .Status .Namespaces , "," ),
1755- }).Debug ("copying csv to targets" )
1777+ if len (operatorGroup .Status .Namespaces ) == 1 && operatorGroup .Status .Namespaces [0 ] == "" {
1778+ logger .Debug ("copying csv to targets in all namespaces" )
1779+ } else {
1780+ logger .WithFields (logrus.Fields {
1781+ "targetNamespaces" : strings .Join (operatorGroup .Status .Namespaces , "," ),
1782+ }).Debug ("copying csv to targets" )
1783+ }
17561784
17571785 copiedCSVsAreEnabled , err := a .copiedCSVsAreEnabled ()
17581786 if err != nil {
@@ -1910,6 +1938,55 @@ func (a *Operator) createCSVCopyingDisabledEvent(csv *v1alpha1.ClusterServiceVer
19101938 return nil
19111939}
19121940
1941+ func GetCopiedNamespace (c * v1alpha1.ClusterServiceVersion ) string {
1942+ annotations := c .GetAnnotations ()
1943+ if annotations != nil {
1944+ operatorNamespace , ok := annotations [v1alpha1 .OperatorGroupNamespaceAnnotationKey ]
1945+ if ok && c .GetNamespace () != operatorNamespace {
1946+ return operatorNamespace
1947+ }
1948+ }
1949+
1950+ if labels := c .GetLabels (); labels != nil {
1951+ if l , ok := labels [v1alpha1 .CopiedLabelKey ]; ok {
1952+ return l
1953+ }
1954+ }
1955+ return ""
1956+ }
1957+
1958+ func (a * Operator ) syncRevertCsv (obj interface {}) error {
1959+ csv , ok := obj .(* v1alpha1.ClusterServiceVersion )
1960+ if ! ok {
1961+ a .logger .Debugf ("wrong type: %#v" , obj )
1962+ return fmt .Errorf ("casting ClusterServiceVersion failed" )
1963+ }
1964+ logger := a .logger .WithField ("csv" , fmt .Sprintf ("%s/%s" , csv .GetNamespace (), csv .GetName ()))
1965+ logger .Info ("syncRevertCsv" )
1966+ ns := GetCopiedNamespace (csv )
1967+ if ns == "" {
1968+ logger .Info ("syncRevertCsv: Unable to get copied-from namespace" )
1969+ return nil
1970+ }
1971+ prototype , err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (ns ).Get (context .TODO (), csv .GetName (), metav1.GetOptions {})
1972+ if err != nil {
1973+ logger .Info ("syncRevertCsv: Unable to get prototype" )
1974+ return err
1975+ }
1976+ var copyPrototype v1alpha1.ClusterServiceVersion
1977+ csvCopyPrototype (prototype , & copyPrototype )
1978+ specHash , statusHash , err := copyableCSVHash (& copyPrototype )
1979+ if err != nil {
1980+ logger .Info ("syncRevertCsv: Unable to hash" )
1981+ return err
1982+ }
1983+ _ , err = a .copyToNamespace (& copyPrototype , ns , csv .GetNamespace (), specHash , statusHash )
1984+ if err != nil {
1985+ logger .WithError (err ).Info ("syncRevertCsv: copyToNamespace failed" )
1986+ }
1987+ return err
1988+ }
1989+
19131990func (a * Operator ) syncGcCsv (obj interface {}) (syncError error ) {
19141991 clusterServiceVersion , ok := obj .(* v1alpha1.ClusterServiceVersion )
19151992 if ! ok {
0 commit comments