Skip to content

Commit 041603c

Browse files
author
Per Goncalves da Silva
committed
Refactor subscription reconciler away from kubestate
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent d68cd00 commit 041603c

File tree

11 files changed

+763
-3142
lines changed

11 files changed

+763
-3142
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,27 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
332332
return nil, err
333333
}
334334

335+
// Namespace sync for resolving subscriptions
336+
namespaceInformer := informers.NewSharedInformerFactory(op.opClient.KubernetesInterface(), resyncPeriod()).Core().V1().Namespaces()
337+
op.lister.CoreV1().RegisterNamespaceLister(namespaceInformer.Lister())
338+
op.nsResolveQueue = workqueue.NewTypedRateLimitingQueueWithConfig[any](workqueue.DefaultTypedControllerRateLimiter[any](),
339+
workqueue.TypedRateLimitingQueueConfig[any]{
340+
Name: "resolve",
341+
})
342+
namespaceQueueInformer, err := queueinformer.NewQueueInformer(
343+
ctx,
344+
queueinformer.WithLogger(op.logger),
345+
queueinformer.WithQueue(op.nsResolveQueue),
346+
queueinformer.WithInformer(namespaceInformer.Informer()),
347+
queueinformer.WithSyncer(queueinformer.LegacySyncHandler(op.syncResolvingNamespace).ToSyncer()),
348+
)
349+
if err != nil {
350+
return nil, err
351+
}
352+
if err := op.RegisterQueueInformer(namespaceQueueInformer); err != nil {
353+
return nil, err
354+
}
355+
335356
// Wire Subscriptions
336357
subInformer := crInformerFactory.Operators().V1alpha1().Subscriptions()
337358
op.lister.OperatorsV1alpha1().RegisterSubscriptionLister(metav1.NamespaceAll, subInformer.Lister())
@@ -355,7 +376,7 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
355376
subscription.WithCatalogInformer(catsrcInformer.Informer()),
356377
subscription.WithInstallPlanInformer(ipInformer.Informer()),
357378
subscription.WithSubscriptionQueue(subQueue),
358-
subscription.WithAppendedReconcilers(subscription.ReconcilerFromLegacySyncHandler(op.syncSubscriptions, nil)),
379+
subscription.WithNamespaceResolveQueue(op.nsResolveQueue),
359380
subscription.WithRegistryReconcilerFactory(op.reconciler),
360381
subscription.WithGlobalCatalogNamespace(op.namespace),
361382
subscription.WithSourceProvider(op.resolverSourceProvider),
@@ -742,27 +763,6 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
742763
return nil, err
743764
}
744765

745-
// Namespace sync for resolving subscriptions
746-
namespaceInformer := informers.NewSharedInformerFactory(op.opClient.KubernetesInterface(), resyncPeriod()).Core().V1().Namespaces()
747-
op.lister.CoreV1().RegisterNamespaceLister(namespaceInformer.Lister())
748-
op.nsResolveQueue = workqueue.NewTypedRateLimitingQueueWithConfig[any](workqueue.DefaultTypedControllerRateLimiter[any](),
749-
workqueue.TypedRateLimitingQueueConfig[any]{
750-
Name: "resolve",
751-
})
752-
namespaceQueueInformer, err := queueinformer.NewQueueInformer(
753-
ctx,
754-
queueinformer.WithLogger(op.logger),
755-
queueinformer.WithQueue(op.nsResolveQueue),
756-
queueinformer.WithInformer(namespaceInformer.Informer()),
757-
queueinformer.WithSyncer(queueinformer.LegacySyncHandler(op.syncResolvingNamespace).ToSyncer()),
758-
)
759-
if err != nil {
760-
return nil, err
761-
}
762-
if err := op.RegisterQueueInformer(namespaceQueueInformer); err != nil {
763-
return nil, err
764-
}
765-
766766
op.sources.Start(context.Background())
767767

768768
return op, nil
@@ -1342,6 +1342,11 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
13421342
return err
13431343
}
13441344

1345+
// Remove any sticky ResolutionFailure condition
1346+
for _, sub := range subs {
1347+
sub.Status.RemoveConditions(v1alpha1.SubscriptionResolutionFailed)
1348+
}
1349+
13451350
// Attempt to unpack bundles before installing
13461351
// Note: This should probably use the attenuated client to prevent users from resolving resources they otherwise don't have access to.
13471352
if len(bundleLookups) > 0 {
@@ -1499,16 +1504,9 @@ func (o *Operator) syncResolvingNamespace(obj interface{}) error {
14991504
return nil
15001505
}
15011506

1502-
func (o *Operator) syncSubscriptions(obj interface{}) error {
1503-
sub, ok := obj.(*v1alpha1.Subscription)
1504-
if !ok {
1505-
o.logger.Infof("wrong type: %#v", obj)
1506-
return fmt.Errorf("casting Subscription failed")
1507-
}
1508-
1507+
func (o *Operator) syncSubscriptions(_ context.Context, sub *v1alpha1.Subscription) (*v1alpha1.Subscription, error) {
15091508
o.nsResolveQueue.Add(sub.GetNamespace())
1510-
1511-
return nil
1509+
return sub, nil
15121510
}
15131511

15141512
// syncOperatorGroups requeues the namespace resolution queue on changes to an operatorgroup
@@ -2850,31 +2848,11 @@ func (o *Operator) getUpdatedOwnerReferences(refs []metav1.OwnerReference, names
28502848
}
28512849

28522850
func (o *Operator) listSubscriptions(namespace string) (subs []*v1alpha1.Subscription, err error) {
2853-
list, err := o.client.OperatorsV1alpha1().Subscriptions(namespace).List(context.TODO(), metav1.ListOptions{})
2854-
if err != nil {
2855-
return
2856-
}
2857-
2858-
subs = make([]*v1alpha1.Subscription, 0)
2859-
for i := range list.Items {
2860-
subs = append(subs, &list.Items[i])
2861-
}
2862-
2863-
return
2851+
return o.lister.OperatorsV1alpha1().SubscriptionLister().Subscriptions(namespace).List(labels.Everything())
28642852
}
28652853

28662854
func (o *Operator) listInstallPlans(namespace string) (ips []*v1alpha1.InstallPlan, err error) {
2867-
list, err := o.client.OperatorsV1alpha1().InstallPlans(namespace).List(context.TODO(), metav1.ListOptions{})
2868-
if err != nil {
2869-
return
2870-
}
2871-
2872-
ips = make([]*v1alpha1.InstallPlan, 0)
2873-
for i := range list.Items {
2874-
ips = append(ips, &list.Items[i])
2875-
}
2876-
2877-
return
2855+
return o.lister.OperatorsV1alpha1().InstallPlanLister().InstallPlans(namespace).List(labels.Everything())
28782856
}
28792857

28802858
// competingCRDOwnersExist returns true if there exists a CSV that owns at least one of the given CSVs owned CRDs (that's not the given CSV)

0 commit comments

Comments
 (0)