Skip to content

Commit 21ac339

Browse files
Merge pull request #1036 from tmshort/OCPBUGS-59253
[release-4.17] OCPBUGS-59253: Reduce Frequency of Update Requests for Copied CSVs (#3597)
2 parents 9fbe7d7 + e4bc847 commit 21ac339

File tree

15 files changed

+492
-304
lines changed

15 files changed

+492
-304
lines changed

staging/operator-lifecycle-manager/pkg/controller/operators/catalog/operator.go

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import (
6262
olmerrors "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/errors"
6363
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
6464
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog/subscription"
65-
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/internal/pruning"
65+
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/internal/listerwatcher"
6666
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
6767
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/grpc"
6868
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler"
@@ -228,38 +228,53 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
228228

229229
// Fields are pruned from local copies of the objects managed
230230
// by this informer in order to reduce cached size.
231-
prunedCSVInformer := cache.NewSharedIndexInformer(
232-
pruning.NewListerWatcher(op.client, metav1.NamespaceAll,
231+
prunedCSVInformer := cache.NewSharedIndexInformerWithOptions(
232+
listerwatcher.NewListerWatcher(
233+
op.client,
234+
metav1.NamespaceAll,
233235
func(options *metav1.ListOptions) {
234236
options.LabelSelector = fmt.Sprintf("!%s", v1alpha1.CopiedLabelKey)
235237
},
236-
pruning.PrunerFunc(func(csv *v1alpha1.ClusterServiceVersion) {
237-
*csv = v1alpha1.ClusterServiceVersion{
238-
TypeMeta: csv.TypeMeta,
239-
ObjectMeta: metav1.ObjectMeta{
240-
Name: csv.Name,
241-
Namespace: csv.Namespace,
242-
Labels: csv.Labels,
243-
Annotations: csv.Annotations,
244-
},
245-
Spec: v1alpha1.ClusterServiceVersionSpec{
246-
CustomResourceDefinitions: csv.Spec.CustomResourceDefinitions,
247-
APIServiceDefinitions: csv.Spec.APIServiceDefinitions,
248-
Replaces: csv.Spec.Replaces,
249-
Version: csv.Spec.Version,
250-
},
251-
Status: v1alpha1.ClusterServiceVersionStatus{
252-
Phase: csv.Status.Phase,
253-
Reason: csv.Status.Reason,
254-
},
255-
}
256-
})),
238+
),
257239
&v1alpha1.ClusterServiceVersion{},
258-
resyncPeriod(),
259-
cache.Indexers{
260-
cache.NamespaceIndex: cache.MetaNamespaceIndexFunc,
240+
cache.SharedIndexInformerOptions{
241+
ResyncPeriod: resyncPeriod(),
242+
Indexers: cache.Indexers{
243+
cache.NamespaceIndex: cache.MetaNamespaceIndexFunc,
244+
},
261245
},
262246
)
247+
248+
// Transformed the CSV to be just the necessary data
249+
prunedCSVTransformFunc := func(i interface{}) (interface{}, error) {
250+
if csv, ok := i.(*v1alpha1.ClusterServiceVersion); ok {
251+
*csv = v1alpha1.ClusterServiceVersion{
252+
TypeMeta: csv.TypeMeta,
253+
ObjectMeta: metav1.ObjectMeta{
254+
Name: csv.Name,
255+
Namespace: csv.Namespace,
256+
Labels: csv.Labels,
257+
Annotations: csv.Annotations,
258+
},
259+
Spec: v1alpha1.ClusterServiceVersionSpec{
260+
CustomResourceDefinitions: csv.Spec.CustomResourceDefinitions,
261+
APIServiceDefinitions: csv.Spec.APIServiceDefinitions,
262+
Replaces: csv.Spec.Replaces,
263+
Version: csv.Spec.Version,
264+
},
265+
Status: v1alpha1.ClusterServiceVersionStatus{
266+
Phase: csv.Status.Phase,
267+
Reason: csv.Status.Reason,
268+
},
269+
}
270+
return csv, nil
271+
}
272+
return nil, fmt.Errorf("unable to convert input to CSV")
273+
}
274+
275+
if err := prunedCSVInformer.SetTransform(prunedCSVTransformFunc); err != nil {
276+
return nil, err
277+
}
263278
csvLister := operatorsv1alpha1listers.NewClusterServiceVersionLister(prunedCSVInformer.GetIndexer())
264279
op.lister.OperatorsV1alpha1().RegisterClusterServiceVersionLister(metav1.NamespaceAll, csvLister)
265280
if err := op.RegisterInformer(prunedCSVInformer); err != nil {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package listerwatcher
2+
3+
import (
4+
"context"
5+
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
"k8s.io/apimachinery/pkg/runtime"
8+
"k8s.io/apimachinery/pkg/watch"
9+
"k8s.io/client-go/tools/cache"
10+
11+
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
12+
)
13+
14+
func NewListerWatcher(client versioned.Interface, namespace string, override func(*metav1.ListOptions)) cache.ListerWatcher {
15+
return &cache.ListWatch{
16+
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
17+
override(&options)
18+
return client.OperatorsV1alpha1().ClusterServiceVersions(namespace).List(context.TODO(), options)
19+
},
20+
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
21+
override(&options)
22+
return client.OperatorsV1alpha1().ClusterServiceVersions(namespace).Watch(context.TODO(), options)
23+
},
24+
}
25+
}

staging/operator-lifecycle-manager/pkg/controller/operators/internal/pruning/listerwatcher.go

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)