Skip to content

Commit

Permalink
Use global informers in scheduling controller
Browse files Browse the repository at this point in the history
Signed-off-by: David Festal <dfestal@redhat.com>
  • Loading branch information
davidfestal committed Apr 5, 2023
1 parent 419199c commit 850d52b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
17 changes: 12 additions & 5 deletions pkg/reconciler/scheduling/placement/placement_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const (
func NewController(
kcpClusterClient kcpclientset.ClusterInterface,
namespaceInformer kcpcorev1informers.NamespaceClusterInformer,
locationInformer schedulingv1alpha1informers.LocationClusterInformer,
locationInformer, globalLocationInformer schedulingv1alpha1informers.LocationClusterInformer,
placementInformer schedulingv1alpha1informers.PlacementClusterInformer,
) (*controller, error) {
queue := workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), ControllerName)
Expand All @@ -78,8 +78,13 @@ func NewController(

namespaceLister: namespaceInformer.Lister(),

locationLister: locationInformer.Lister(),
locationIndexer: locationInformer.Informer().GetIndexer(),
listLocationsByPath: func(path logicalcluster.Path) ([]*schedulingv1alpha1.Location, error) {
objs, err := indexers.ByIndexWithFallback[*schedulingv1alpha1.Location](locationInformer.Informer().GetIndexer(), globalLocationInformer.Informer().GetIndexer(), indexers.ByLogicalClusterPath, path.String())
if err != nil {
return nil, err
}
return objs, nil
},

placementLister: placementInformer.Lister(),
placementIndexer: placementInformer.Informer().GetIndexer(),
Expand All @@ -96,6 +101,9 @@ func NewController(
indexers.AddIfNotPresentOrDie(locationInformer.Informer().GetIndexer(), cache.Indexers{
indexers.ByLogicalClusterPath: indexers.IndexByLogicalClusterPath,
})
indexers.AddIfNotPresentOrDie(globalLocationInformer.Informer().GetIndexer(), cache.Indexers{
indexers.ByLogicalClusterPath: indexers.IndexByLogicalClusterPath,
})

// namespaceBlocklist holds a set of namespaces that should never be synced from kcp to physical clusters.
var namespaceBlocklist = sets.NewString("kube-system", "kube-public", "kube-node-lease")
Expand Down Expand Up @@ -163,8 +171,7 @@ type controller struct {

namespaceLister corev1listers.NamespaceClusterLister

locationLister schedulingv1alpha1listers.LocationClusterLister
locationIndexer cache.Indexer
listLocationsByPath func(path logicalcluster.Path) ([]*schedulingv1alpha1.Location, error)

placementLister schedulingv1alpha1listers.PlacementClusterLister
placementIndexer cache.Indexer
Expand Down
13 changes: 0 additions & 13 deletions pkg/reconciler/scheduling/placement/placement_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
utilserrors "k8s.io/apimachinery/pkg/util/errors"

"github.com/kcp-dev/kcp/pkg/indexers"
schedulingv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/scheduling/v1alpha1"
)

Expand Down Expand Up @@ -67,18 +66,6 @@ func (c *controller) reconcile(ctx context.Context, placement *schedulingv1alpha
return utilserrors.NewAggregate(errs)
}

func (c *controller) listLocationsByPath(path logicalcluster.Path) ([]*schedulingv1alpha1.Location, error) {
objs, err := c.locationIndexer.ByIndex(indexers.ByLogicalClusterPath, path.String())
if err != nil {
return nil, err
}
ret := make([]*schedulingv1alpha1.Location, 0, len(objs))
for _, obj := range objs {
ret = append(ret, obj.(*schedulingv1alpha1.Location))
}
return ret, nil
}

func (c *controller) listNamespacesWithAnnotation(clusterName logicalcluster.Name) ([]*corev1.Namespace, error) {
items, err := c.namespaceLister.Cluster(clusterName).List(labels.Everything())
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions tmc/pkg/server/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func (s *Server) installSchedulingPlacementController(ctx context.Context, confi
kcpClusterClient,
s.Core.KubeSharedInformerFactory.Core().V1().Namespaces(),
s.Core.KcpSharedInformerFactory.Scheduling().V1alpha1().Locations(),
s.Core.CacheKcpSharedInformerFactory.Scheduling().V1alpha1().Locations(),
s.Core.KcpSharedInformerFactory.Scheduling().V1alpha1().Placements(),
)
if err != nil {
Expand Down

0 comments on commit 850d52b

Please sign in to comment.