fix unhandled errors (#104)

Signed-off-by: haoqing0110 <qhao@redhat.com>
This commit is contained in:
Qing Hao
2023-03-22 16:35:31 +08:00
committed by GitHub
parent 75493f3ab5
commit 2c74434fa7
2 changed files with 25 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package scheduling
import (
"fmt"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/tools/cache"
@@ -42,14 +43,20 @@ func newEnqueuer(
clusterSetInformer clusterinformerv1beta2.ManagedClusterSetInformer,
placementInformer clusterinformerv1beta1.PlacementInformer,
clusterSetBindingInformer clusterinformerv1beta2.ManagedClusterSetBindingInformer) *enqueuer {
placementInformer.Informer().AddIndexers(cache.Indexers{
err := placementInformer.Informer().AddIndexers(cache.Indexers{
placementsByScore: indexPlacementsByScore,
placementsByClusterSetBinding: indexPlacementByClusterSetBinding,
})
if err != nil {
runtime.HandleError(err)
}
clusterSetBindingInformer.Informer().AddIndexers(cache.Indexers{
err = clusterSetBindingInformer.Informer().AddIndexers(cache.Indexers{
clustersetBindingsByClusterSet: indexClusterSetBindingByClusterSet,
})
if err != nil {
runtime.HandleError(err)
}
return &enqueuer{
queue: queue,

View File

@@ -99,9 +99,12 @@ func NewSchedulingController(
// informers/listers of clusterset/clustersetbinding/placement are synced during
// controller booting. But that should not cause any problem because all existing
// placements will be enqueued by the controller anyway when booting.
clusterInformer.Informer().AddEventHandler(&clusterEventHandler{
_, err := clusterInformer.Informer().AddEventHandler(&clusterEventHandler{
enqueuer: enQueuer,
})
if err != nil {
utilruntime.HandleError(err)
}
// setup event handler for clusterset informer
// Once a clusterset changes, clusterSetEventHandler enqueues all placements which are
@@ -109,13 +112,16 @@ func NewSchedulingController(
// informers/listers of clustersetbinding/placement are synced during controller
// booting. But that should not cause any problem because all existing placements will
// be enqueued by the controller anyway when booting.
clusterSetInformer.Informer().AddEventHandler(&cache.ResourceEventHandlerFuncs{
_, err = clusterSetInformer.Informer().AddEventHandler(&cache.ResourceEventHandlerFuncs{
AddFunc: enQueuer.enqueueClusterSet,
UpdateFunc: func(oldObj, newObj interface{}) {
enQueuer.enqueueClusterSet(newObj)
},
DeleteFunc: enQueuer.enqueueClusterSet,
})
if err != nil {
utilruntime.HandleError(err)
}
// setup event handler for clustersetbinding informer
// Once a clustersetbinding changes, clusterSetBindingEventHandler enqueues all placements
@@ -123,22 +129,28 @@ func NewSchedulingController(
// the informers/listers of clusterset/placement are synced during controller booting. But
// that should not cause any problem because all existing placements will be enqueued by
// the controller anyway when booting.
clusterSetBindingInformer.Informer().AddEventHandler(&cache.ResourceEventHandlerFuncs{
_, err = clusterSetBindingInformer.Informer().AddEventHandler(&cache.ResourceEventHandlerFuncs{
AddFunc: enQueuer.enqueueClusterSetBinding,
UpdateFunc: func(oldObj, newObj interface{}) {
enQueuer.enqueueClusterSetBinding(newObj)
},
DeleteFunc: enQueuer.enqueueClusterSetBinding,
})
if err != nil {
utilruntime.HandleError(err)
}
// setup event handler for placementscore informer
placementScoreInformer.Informer().AddEventHandler(&cache.ResourceEventHandlerFuncs{
_, err = placementScoreInformer.Informer().AddEventHandler(&cache.ResourceEventHandlerFuncs{
AddFunc: enQueuer.enqueuePlacementScore,
UpdateFunc: func(oldObj, newObj interface{}) {
enQueuer.enqueuePlacementScore(newObj)
},
DeleteFunc: enQueuer.enqueuePlacementScore,
})
if err != nil {
utilruntime.HandleError(err)
}
return factory.New().
WithSyncContext(syncCtx).