-
Notifications
You must be signed in to change notification settings - Fork 551
OCPBUGS-17157: pkg/controller: use a metadata watch for CRDs #3014
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ import ( | |
corev1 "k8s.io/api/core/v1" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
extinf "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -541,14 +540,25 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat | |
return nil, err | ||
} | ||
|
||
// Register CustomResourceDefinition QueueInformer | ||
crdInformer := extinf.NewSharedInformerFactory(op.opClient.ApiextensionsInterface(), config.resyncPeriod()).Apiextensions().V1().CustomResourceDefinitions() | ||
// Register CustomResourceDefinition QueueInformer. Object metadata requests are used | ||
// by this informer in order to reduce cached size. | ||
gvr := apiextensionsv1.SchemeGroupVersion.WithResource("customresourcedefinitions") | ||
crdInformer := metadatainformer.NewFilteredMetadataInformer( | ||
config.metadataClient, | ||
gvr, | ||
metav1.NamespaceAll, | ||
config.resyncPeriod(), | ||
cache.Indexers{}, | ||
nil, | ||
).Informer() | ||
crdLister := metadatalister.New(crdInformer.GetIndexer(), gvr) | ||
informersByNamespace[metav1.NamespaceAll].CRDInformer = crdInformer | ||
op.lister.APIExtensionsV1().RegisterCustomResourceDefinitionLister(crdInformer.Lister()) | ||
informersByNamespace[metav1.NamespaceAll].CRDLister = crdLister | ||
op.lister.APIExtensionsV1().RegisterCustomResourceDefinitionLister(crdLister) | ||
crdQueueInformer, err := queueinformer.NewQueueInformer( | ||
ctx, | ||
queueinformer.WithLogger(op.logger), | ||
queueinformer.WithInformer(crdInformer.Informer()), | ||
queueinformer.WithInformer(crdInformer), | ||
queueinformer.WithSyncer(k8sSyncer), | ||
) | ||
if err != nil { | ||
|
@@ -1183,7 +1193,7 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) { | |
} | ||
|
||
for i, crdName := range desc.ConversionCRDs { | ||
crd, err := a.lister.APIExtensionsV1().CustomResourceDefinitionLister().Get(crdName) | ||
crd, err := a.opClient.ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Get(context.TODO(), crdName, metav1.GetOptions{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the crux of the trade-off. In the rare case that a CSV is deleted, we incur server cost and latency to do a live GET for the data we need. Better than holding onto 20MiB of every CRD ever when we would only ever be concerned with a tiny subset, and with the spec of that tiny subset in an even smaller set of cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it's an improvement... |
||
if err != nil { | ||
logger.Errorf("error getting CRD %v which was defined in CSVs spec.WebhookDefinition[%d]: %v\n", crdName, i, err) | ||
continue | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary but the DX of watching 10k lines of output scroll by on success makes it impossible to find test failures and should be an anti-pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1000