Skip to content

OCPBUGS-58259: Reduce Frequency of Update Requests for Copied CSVs (#3597) [release-4.19] #1030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import (
olmerrors "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/errors"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog/subscription"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/internal/pruning"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/internal/listerwatcher"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/grpc"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/reconciler"
Expand Down Expand Up @@ -228,38 +228,53 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo

// Fields are pruned from local copies of the objects managed
// by this informer in order to reduce cached size.
prunedCSVInformer := cache.NewSharedIndexInformer(
pruning.NewListerWatcher(op.client, metav1.NamespaceAll,
prunedCSVInformer := cache.NewSharedIndexInformerWithOptions(
listerwatcher.NewListerWatcher(
op.client,
metav1.NamespaceAll,
func(options *metav1.ListOptions) {
options.LabelSelector = fmt.Sprintf("!%s", v1alpha1.CopiedLabelKey)
},
pruning.PrunerFunc(func(csv *v1alpha1.ClusterServiceVersion) {
*csv = v1alpha1.ClusterServiceVersion{
TypeMeta: csv.TypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: csv.Name,
Namespace: csv.Namespace,
Labels: csv.Labels,
Annotations: csv.Annotations,
},
Spec: v1alpha1.ClusterServiceVersionSpec{
CustomResourceDefinitions: csv.Spec.CustomResourceDefinitions,
APIServiceDefinitions: csv.Spec.APIServiceDefinitions,
Replaces: csv.Spec.Replaces,
Version: csv.Spec.Version,
},
Status: v1alpha1.ClusterServiceVersionStatus{
Phase: csv.Status.Phase,
Reason: csv.Status.Reason,
},
}
})),
),
&v1alpha1.ClusterServiceVersion{},
resyncPeriod(),
cache.Indexers{
cache.NamespaceIndex: cache.MetaNamespaceIndexFunc,
cache.SharedIndexInformerOptions{
ResyncPeriod: resyncPeriod(),
Indexers: cache.Indexers{
cache.NamespaceIndex: cache.MetaNamespaceIndexFunc,
},
},
)

// Transformed the CSV to be just the necessary data
prunedCSVTransformFunc := func(i interface{}) (interface{}, error) {
if csv, ok := i.(*v1alpha1.ClusterServiceVersion); ok {
*csv = v1alpha1.ClusterServiceVersion{
TypeMeta: csv.TypeMeta,
ObjectMeta: metav1.ObjectMeta{
Name: csv.Name,
Namespace: csv.Namespace,
Labels: csv.Labels,
Annotations: csv.Annotations,
},
Spec: v1alpha1.ClusterServiceVersionSpec{
CustomResourceDefinitions: csv.Spec.CustomResourceDefinitions,
APIServiceDefinitions: csv.Spec.APIServiceDefinitions,
Replaces: csv.Spec.Replaces,
Version: csv.Spec.Version,
},
Status: v1alpha1.ClusterServiceVersionStatus{
Phase: csv.Status.Phase,
Reason: csv.Status.Reason,
},
}
return csv, nil
}
return nil, fmt.Errorf("unable to convert input to CSV")
}

if err := prunedCSVInformer.SetTransform(prunedCSVTransformFunc); err != nil {
return nil, err
}
csvLister := operatorsv1alpha1listers.NewClusterServiceVersionLister(prunedCSVInformer.GetIndexer())
op.lister.OperatorsV1alpha1().RegisterClusterServiceVersionLister(metav1.NamespaceAll, csvLister)
if err := op.RegisterInformer(prunedCSVInformer); err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package listerwatcher

import (
"context"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/tools/cache"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
)

func NewListerWatcher(client versioned.Interface, namespace string, override func(*metav1.ListOptions)) cache.ListerWatcher {
return &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
override(&options)
return client.OperatorsV1alpha1().ClusterServiceVersions(namespace).List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
override(&options)
return client.OperatorsV1alpha1().ClusterServiceVersions(namespace).Watch(context.TODO(), options)
},
}
}

This file was deleted.

Loading