Unify the dynamic client name for work_status_controller

Signed-off-by: lonelyCZ <531187475@qq.com>
This commit is contained in:
lonelyCZ 2022-10-09 10:25:26 +08:00
parent 49771154d3
commit 3bcee9db07
3 changed files with 32 additions and 32 deletions

View File

@ -305,18 +305,18 @@ func startExecutionController(ctx controllerscontext.Context) (bool, error) {
func startWorkStatusController(ctx controllerscontext.Context) (bool, error) { func startWorkStatusController(ctx controllerscontext.Context) (bool, error) {
workStatusController := &status.WorkStatusController{ workStatusController := &status.WorkStatusController{
Client: ctx.Mgr.GetClient(), Client: ctx.Mgr.GetClient(),
EventRecorder: ctx.Mgr.GetEventRecorderFor(status.WorkStatusControllerName), EventRecorder: ctx.Mgr.GetEventRecorderFor(status.WorkStatusControllerName),
RESTMapper: ctx.Mgr.GetRESTMapper(), RESTMapper: ctx.Mgr.GetRESTMapper(),
InformerManager: genericmanager.GetInstance(), InformerManager: genericmanager.GetInstance(),
StopChan: ctx.StopChan, StopChan: ctx.StopChan,
ObjectWatcher: ctx.ObjectWatcher, ObjectWatcher: ctx.ObjectWatcher,
PredicateFunc: helper.NewExecutionPredicateOnAgent(), PredicateFunc: helper.NewExecutionPredicateOnAgent(),
ClusterClientSetFunc: util.NewClusterDynamicClientSetForAgent, ClusterDynamicClientSetFunc: util.NewClusterDynamicClientSetForAgent,
ClusterCacheSyncTimeout: ctx.Opts.ClusterCacheSyncTimeout, ClusterCacheSyncTimeout: ctx.Opts.ClusterCacheSyncTimeout,
ConcurrentWorkStatusSyncs: ctx.Opts.ConcurrentWorkSyncs, ConcurrentWorkStatusSyncs: ctx.Opts.ConcurrentWorkSyncs,
RateLimiterOptions: ctx.Opts.RateLimiterOptions, RateLimiterOptions: ctx.Opts.RateLimiterOptions,
ResourceInterpreter: ctx.ResourceInterpreter, ResourceInterpreter: ctx.ResourceInterpreter,
} }
workStatusController.RunWorkQueue() workStatusController.RunWorkQueue()
if err := workStatusController.SetupWithManager(ctx.Mgr); err != nil { if err := workStatusController.SetupWithManager(ctx.Mgr); err != nil {

View File

@ -348,18 +348,18 @@ func startExecutionController(ctx controllerscontext.Context) (enabled bool, err
func startWorkStatusController(ctx controllerscontext.Context) (enabled bool, err error) { func startWorkStatusController(ctx controllerscontext.Context) (enabled bool, err error) {
opts := ctx.Opts opts := ctx.Opts
workStatusController := &status.WorkStatusController{ workStatusController := &status.WorkStatusController{
Client: ctx.Mgr.GetClient(), Client: ctx.Mgr.GetClient(),
EventRecorder: ctx.Mgr.GetEventRecorderFor(status.WorkStatusControllerName), EventRecorder: ctx.Mgr.GetEventRecorderFor(status.WorkStatusControllerName),
RESTMapper: ctx.Mgr.GetRESTMapper(), RESTMapper: ctx.Mgr.GetRESTMapper(),
InformerManager: genericmanager.GetInstance(), InformerManager: genericmanager.GetInstance(),
StopChan: ctx.StopChan, StopChan: ctx.StopChan,
ObjectWatcher: ctx.ObjectWatcher, ObjectWatcher: ctx.ObjectWatcher,
PredicateFunc: helper.NewExecutionPredicate(ctx.Mgr), PredicateFunc: helper.NewExecutionPredicate(ctx.Mgr),
ClusterClientSetFunc: util.NewClusterDynamicClientSet, ClusterDynamicClientSetFunc: util.NewClusterDynamicClientSet,
ClusterCacheSyncTimeout: opts.ClusterCacheSyncTimeout, ClusterCacheSyncTimeout: opts.ClusterCacheSyncTimeout,
ConcurrentWorkStatusSyncs: opts.ConcurrentWorkSyncs, ConcurrentWorkStatusSyncs: opts.ConcurrentWorkSyncs,
RateLimiterOptions: ctx.Opts.RateLimiterOptions, RateLimiterOptions: ctx.Opts.RateLimiterOptions,
ResourceInterpreter: ctx.ResourceInterpreter, ResourceInterpreter: ctx.ResourceInterpreter,
} }
workStatusController.RunWorkQueue() workStatusController.RunWorkQueue()
if err := workStatusController.SetupWithManager(ctx.Mgr); err != nil { if err := workStatusController.SetupWithManager(ctx.Mgr); err != nil {

View File

@ -47,13 +47,13 @@ type WorkStatusController struct {
StopChan <-chan struct{} StopChan <-chan struct{}
worker util.AsyncWorker // worker process resources periodic from rateLimitingQueue. worker util.AsyncWorker // worker process resources periodic from rateLimitingQueue.
// ConcurrentWorkStatusSyncs is the number of Work status that are allowed to sync concurrently. // ConcurrentWorkStatusSyncs is the number of Work status that are allowed to sync concurrently.
ConcurrentWorkStatusSyncs int ConcurrentWorkStatusSyncs int
ObjectWatcher objectwatcher.ObjectWatcher ObjectWatcher objectwatcher.ObjectWatcher
PredicateFunc predicate.Predicate PredicateFunc predicate.Predicate
ClusterClientSetFunc func(clusterName string, client client.Client) (*util.DynamicClusterClient, error) ClusterDynamicClientSetFunc func(clusterName string, client client.Client) (*util.DynamicClusterClient, error)
ClusterCacheSyncTimeout metav1.Duration ClusterCacheSyncTimeout metav1.Duration
RateLimiterOptions ratelimiterflag.Options RateLimiterOptions ratelimiterflag.Options
ResourceInterpreter resourceinterpreter.ResourceInterpreter ResourceInterpreter resourceinterpreter.ResourceInterpreter
} }
// Reconcile performs a full reconciliation for the object referred to by the Request. // Reconcile performs a full reconciliation for the object referred to by the Request.
@ -462,7 +462,7 @@ func (c *WorkStatusController) getSingleClusterManager(cluster *clusterv1alpha1.
// the cache in informer manager should be updated. // the cache in informer manager should be updated.
singleClusterInformerManager := c.InformerManager.GetSingleClusterManager(cluster.Name) singleClusterInformerManager := c.InformerManager.GetSingleClusterManager(cluster.Name)
if singleClusterInformerManager == nil { if singleClusterInformerManager == nil {
dynamicClusterClient, err := c.ClusterClientSetFunc(cluster.Name, c.Client) dynamicClusterClient, err := c.ClusterDynamicClientSetFunc(cluster.Name, c.Client)
if err != nil { if err != nil {
klog.Errorf("Failed to build dynamic cluster client for cluster %s.", cluster.Name) klog.Errorf("Failed to build dynamic cluster client for cluster %s.", cluster.Name)
return nil, err return nil, err