@@ -18,6 +18,7 @@ import (
18
18
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19
19
"k8s.io/apimachinery/pkg/labels"
20
20
"k8s.io/apimachinery/pkg/runtime"
21
+ "k8s.io/apimachinery/pkg/selection"
21
22
utilclock "k8s.io/apimachinery/pkg/util/clock"
22
23
utilerrors "k8s.io/apimachinery/pkg/util/errors"
23
24
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -30,6 +31,7 @@ import (
30
31
kagg "k8s.io/kube-aggregator/pkg/client/informers/externalversions"
31
32
32
33
"github.com/operator-framework/api/pkg/operators/v1alpha1"
34
+ operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
33
35
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
34
36
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/informers/externalversions"
35
37
operatorsv1alpha1listers "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
@@ -1241,9 +1243,33 @@ func (a *Operator) syncCopyCSV(obj interface{}) (syncError error) {
1241
1243
}).Debug ("copying csv to targets" )
1242
1244
1243
1245
// Check if we need to do any copying / annotation for the operatorgroup
1244
- if err := a .ensureCSVsInNamespaces (clusterServiceVersion , operatorGroup , NewNamespaceSet (operatorGroup .Status .Namespaces )); err != nil {
1245
- logger .WithError (err ).Info ("couldn't copy CSV to target namespaces" )
1246
- syncError = err
1246
+ copyingCSVs := false // TODO: Request OLMConfig singleton
1247
+ namespaceSet := NewNamespaceSet (operatorGroup .Status .Namespaces )
1248
+ if copyingCSVs || ! namespaceSet .IsAllNamespaces () {
1249
+ if err := a .ensureCSVsInNamespaces (clusterServiceVersion , operatorGroup , namespaceSet ); err != nil {
1250
+ logger .WithError (err ).Info ("couldn't copy CSV to target namespaces" )
1251
+ syncError = err
1252
+ }
1253
+ } else {
1254
+ // Todo: What happens with multiple event triggers?
1255
+ go a .recorder .Event (clusterServiceVersion , corev1 .EventTypeWarning , "CopiedCSVsDisabled" , fmt .Sprintf ("CSV copying disabled for %s/%s" , clusterServiceVersion .GetNamespace (), clusterServiceVersion .GetName ()))
1256
+
1257
+ requirement , err := labels .NewRequirement (operatorsv1alpha1 .CopiedLabelKey , selection .Equals , []string {clusterServiceVersion .Namespace })
1258
+ if err != nil {
1259
+ return err
1260
+ }
1261
+
1262
+ copiedCSVs , err := a .copiedCSVLister .List (labels .NewSelector ().Add (* requirement ))
1263
+ if err != nil {
1264
+ return err
1265
+ }
1266
+
1267
+ for _ , copiedCSV := range copiedCSVs {
1268
+ err := a .client .OperatorsV1alpha1 ().ClusterServiceVersions (copiedCSV .Namespace ).Delete (context .TODO (), copiedCSV .Name , metav1.DeleteOptions {})
1269
+ if err != nil && ! k8serrors .IsNotFound (err ) {
1270
+ return err
1271
+ }
1272
+ }
1247
1273
}
1248
1274
1249
1275
return
0 commit comments