mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-24 21:13:16 +00:00
fix: check error of AddEventHandler
This commit is contained in:
committed by
lukasmetzner
parent
a5055cc407
commit
8ef9e53ce5
@@ -128,13 +128,16 @@ func startRouteController(ctx context.Context, initContext ControllerInitContext
|
||||
return nil, false, fmt.Errorf("length of clusterCIDRs is:%v more than max allowed of 2", len(clusterCIDRs))
|
||||
}
|
||||
|
||||
routeController := routecontroller.New(
|
||||
routeController, err := routecontroller.New(
|
||||
routes,
|
||||
completedConfig.ClientBuilder.ClientOrDie(initContext.ClientName),
|
||||
completedConfig.SharedInformers.Core().V1().Nodes(),
|
||||
completedConfig.ComponentConfig.KubeCloudShared.ClusterName,
|
||||
clusterCIDRs,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
go routeController.Run(ctx, completedConfig.ComponentConfig.KubeCloudShared.RouteReconciliationPeriod.Duration, controlexContext.ControllerManagerMetrics)
|
||||
|
||||
return nil, true, nil
|
||||
|
||||
@@ -75,7 +75,13 @@ type RouteController struct {
|
||||
workqueue workqueue.TypedRateLimitingInterface[string]
|
||||
}
|
||||
|
||||
func New(routes cloudprovider.Routes, kubeClient clientset.Interface, nodeInformer coreinformers.NodeInformer, clusterName string, clusterCIDRs []*net.IPNet) *RouteController {
|
||||
func New(
|
||||
routes cloudprovider.Routes,
|
||||
kubeClient clientset.Interface,
|
||||
nodeInformer coreinformers.NodeInformer,
|
||||
clusterName string,
|
||||
clusterCIDRs []*net.IPNet,
|
||||
) (*RouteController, error) {
|
||||
if len(clusterCIDRs) == 0 {
|
||||
klog.Fatal("RouteController: Must specify clusterCIDR.")
|
||||
}
|
||||
@@ -96,7 +102,7 @@ func New(routes cloudprovider.Routes, kubeClient clientset.Interface, nodeInform
|
||||
workqueue.TypedRateLimitingQueueConfig[string]{Name: "Routes"},
|
||||
)
|
||||
|
||||
rc.nodeInformer.Informer().AddEventHandler(
|
||||
_, err := rc.nodeInformer.Informer().AddEventHandler(
|
||||
// It is only necessary to reconcile the routes for any events that have the potential to impact them:
|
||||
// - Node is added
|
||||
// - Node is removed
|
||||
@@ -109,9 +115,12 @@ func New(routes cloudprovider.Routes, kubeClient clientset.Interface, nodeInform
|
||||
DeleteFunc: rc.enqueueReconcile,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return rc
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
func (rc *RouteController) enqueueReconcile(_ interface{}) {
|
||||
|
||||
@@ -77,7 +77,8 @@ func TestIsResponsibleForRoute(t *testing.T) {
|
||||
}
|
||||
client := fake.NewSimpleClientset()
|
||||
informerFactory := informers.NewSharedInformerFactory(client, 0)
|
||||
rc := New(nil, nil, informerFactory.Core().V1().Nodes(), myClusterName, []*net.IPNet{cidr})
|
||||
rc, err := New(nil, nil, informerFactory.Core().V1().Nodes(), myClusterName, []*net.IPNet{cidr})
|
||||
require.NoError(t, err)
|
||||
rc.nodeListerSynced = alwaysReady
|
||||
route := &cloudprovider.Route{
|
||||
Name: testCase.routeName,
|
||||
@@ -457,7 +458,9 @@ func TestReconcile(t *testing.T) {
|
||||
}
|
||||
|
||||
informerFactory := informers.NewSharedInformerFactory(testCase.clientset, 0)
|
||||
rc := New(routes, testCase.clientset, informerFactory.Core().V1().Nodes(), cluster, cidrs)
|
||||
|
||||
rc, err := New(routes, testCase.clientset, informerFactory.Core().V1().Nodes(), cluster, cidrs)
|
||||
require.NoError(t, err)
|
||||
|
||||
recorder := record.NewBroadcaster(record.WithContext(ctx))
|
||||
rc.recorder = recorder.NewRecorder(scheme.Scheme, v1.EventSource{Component: "route_controller"})
|
||||
@@ -493,7 +496,6 @@ func TestReconcile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
var finalRoutes []*cloudprovider.Route
|
||||
var err error
|
||||
timeoutChan := time.After(200 * time.Millisecond)
|
||||
tick := time.NewTicker(10 * time.Millisecond)
|
||||
defer tick.Stop()
|
||||
@@ -588,7 +590,8 @@ func TestHandleNodeUpdate(t *testing.T) {
|
||||
cidrs = append(cidrs, cidr)
|
||||
|
||||
informerFactory := informers.NewSharedInformerFactory(testCase.clientset, 0)
|
||||
rc := New(routes, testCase.clientset, informerFactory.Core().V1().Nodes(), cluster, cidrs)
|
||||
rc, err := New(routes, testCase.clientset, informerFactory.Core().V1().Nodes(), cluster, cidrs)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, rc.workqueue)
|
||||
|
||||
rc.handleNodeUpdate(&node, &testCase.updatedNode)
|
||||
|
||||
Reference in New Issue
Block a user