@@ -307,7 +307,6 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
307
307
// A separate informer solely for CSV copies. Fields
308
308
// are pruned from local copies of the objects managed
309
309
// by this informer in order to reduce cached size.
310
-
311
310
copiedCSVInformer := cache .NewSharedIndexInformerWithOptions (
312
311
listerwatcher .NewListerWatcher (
313
312
op .client ,
@@ -328,6 +327,7 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
328
327
// a hash over the full CSV to store as an annotation
329
328
copiedCSVTransformFunc := func (i interface {}) (interface {}, error ) {
330
329
if csv , ok := i .(* v1alpha1.ClusterServiceVersion ); ok {
330
+ config .logger .WithField ("name" , fmt .Sprintf ("%s/%s" , csv .Namespace , csv .Name )).Info ("Transforming copied CSV" )
331
331
specHash , statusHash , err := copyableCSVHash (csv )
332
332
if err != nil {
333
333
return nil , err
@@ -356,6 +356,28 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
356
356
informersByNamespace [namespace ].CopiedCSVInformer = copiedCSVInformer
357
357
informersByNamespace [namespace ].CopiedCSVLister = op .copiedCSVLister
358
358
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
+
359
381
// Register separate queue for gcing copied csvs
360
382
copiedCSVGCQueue := workqueue .NewTypedRateLimitingQueueWithConfig [types.NamespacedName ](
361
383
workqueue .DefaultTypedControllerRateLimiter [types.NamespacedName ](),
@@ -1723,6 +1745,8 @@ func (a *Operator) syncCopyCSV(obj interface{}) (syncError error) {
1723
1745
return fmt .Errorf ("casting ClusterServiceVersion failed" )
1724
1746
}
1725
1747
1748
+ a .logger .WithField ("name" , fmt .Sprintf ("%s/%s" , clusterServiceVersion .Namespace , clusterServiceVersion .Name )).Info ("syncCopyCSV" )
1749
+
1726
1750
olmConfig , err := a .client .OperatorsV1 ().OLMConfigs ().Get (context .TODO (), "cluster" , metav1.GetOptions {})
1727
1751
if err != nil && ! apierrors .IsNotFound (err ) {
1728
1752
return err
@@ -1750,9 +1774,13 @@ func (a *Operator) syncCopyCSV(obj interface{}) (syncError error) {
1750
1774
return
1751
1775
}
1752
1776
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
+ }
1756
1784
1757
1785
copiedCSVsAreEnabled , err := a .copiedCSVsAreEnabled ()
1758
1786
if err != nil {
@@ -1910,6 +1938,55 @@ func (a *Operator) createCSVCopyingDisabledEvent(csv *v1alpha1.ClusterServiceVer
1910
1938
return nil
1911
1939
}
1912
1940
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
+
1913
1990
func (a * Operator ) syncGcCsv (obj interface {}) (syncError error ) {
1914
1991
clusterServiceVersion , ok := obj .(* v1alpha1.ClusterServiceVersion )
1915
1992
if ! ok {
0 commit comments