Merge pull request #5799 from chaosi-zju/ctrl-name

Ensure controller names are unique when emitting metrics
This commit is contained in:
karmada-bot 2024-11-11 15:37:49 +08:00 committed by GitHub
commit ed3f48cd32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 82 additions and 41 deletions

View File

@ -45,7 +45,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "karmada-operator-controller" ControllerName = "karmada-operator-controller"
// ControllerFinalizerName is the name of the karmada controller finalizer // ControllerFinalizerName is the name of the karmada controller finalizer
@ -185,6 +185,7 @@ func (ctrl *Controller) ensureKarmada(ctx context.Context, karmada *operatorv1al
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (ctrl *Controller) SetupWithManager(mgr controllerruntime.Manager) error { func (ctrl *Controller) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&operatorv1alpha1.Karmada{}, For(&operatorv1alpha1.Karmada{},
builder.WithPredicates(predicate.Funcs{ builder.WithPredicates(predicate.Funcs{
UpdateFunc: ctrl.onKarmadaUpdate, UpdateFunc: ctrl.onKarmadaUpdate,

View File

@ -45,7 +45,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/helper" "github.com/karmada-io/karmada/pkg/util/helper"
) )
// CRBApplicationFailoverControllerName is the controller name that will be used when reporting events. // CRBApplicationFailoverControllerName is the controller name that will be used when reporting events and metrics.
const CRBApplicationFailoverControllerName = "cluster-resource-binding-application-failover-controller" const CRBApplicationFailoverControllerName = "cluster-resource-binding-application-failover-controller"
// CRBApplicationFailoverController is to sync ClusterResourceBinding's application failover behavior. // CRBApplicationFailoverController is to sync ClusterResourceBinding's application failover behavior.
@ -230,6 +230,7 @@ func (c *CRBApplicationFailoverController) SetupWithManager(mgr controllerruntim
} }
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(CRBApplicationFailoverControllerName).
For(&workv1alpha2.ClusterResourceBinding{}, builder.WithPredicates(clusterResourceBindingPredicateFn)). For(&workv1alpha2.ClusterResourceBinding{}, builder.WithPredicates(clusterResourceBindingPredicateFn)).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}). WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
Complete(c) Complete(c)

View File

@ -45,7 +45,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/helper" "github.com/karmada-io/karmada/pkg/util/helper"
) )
// RBApplicationFailoverControllerName is the controller name that will be used when reporting events. // RBApplicationFailoverControllerName is the controller name that will be used when reporting events and metrics.
const RBApplicationFailoverControllerName = "resource-binding-application-failover-controller" const RBApplicationFailoverControllerName = "resource-binding-application-failover-controller"
// RBApplicationFailoverController is to sync ResourceBinding's application failover behavior. // RBApplicationFailoverController is to sync ResourceBinding's application failover behavior.
@ -232,6 +232,7 @@ func (c *RBApplicationFailoverController) SetupWithManager(mgr controllerruntime
} }
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(RBApplicationFailoverControllerName).
For(&workv1alpha2.ResourceBinding{}, builder.WithPredicates(resourceBindingPredicateFn)). For(&workv1alpha2.ResourceBinding{}, builder.WithPredicates(resourceBindingPredicateFn)).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}). WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
Complete(c) Complete(c)

View File

@ -49,7 +49,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/overridemanager" "github.com/karmada-io/karmada/pkg/util/overridemanager"
) )
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
const ControllerName = "binding-controller" const ControllerName = "binding-controller"
// ResourceBindingController is to sync ResourceBinding. // ResourceBindingController is to sync ResourceBinding.
@ -165,7 +165,9 @@ func (c *ResourceBindingController) removeOrphanWorks(ctx context.Context, bindi
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (c *ResourceBindingController) SetupWithManager(mgr controllerruntime.Manager) error { func (c *ResourceBindingController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha2.ResourceBinding{}). return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&workv1alpha2.ResourceBinding{}).
WithEventFilter(predicate.GenerationChangedPredicate{}). WithEventFilter(predicate.GenerationChangedPredicate{}).
Watches(&policyv1alpha1.OverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())). Watches(&policyv1alpha1.OverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
Watches(&policyv1alpha1.ClusterOverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())). Watches(&policyv1alpha1.ClusterOverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).

View File

@ -49,7 +49,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/overridemanager" "github.com/karmada-io/karmada/pkg/util/overridemanager"
) )
// ClusterResourceBindingControllerName is the controller name that will be used when reporting events. // ClusterResourceBindingControllerName is the controller name that will be used when reporting events and metrics.
const ClusterResourceBindingControllerName = "cluster-resource-binding-controller" const ClusterResourceBindingControllerName = "cluster-resource-binding-controller"
// ClusterResourceBindingController is to sync ClusterResourceBinding. // ClusterResourceBindingController is to sync ClusterResourceBinding.
@ -161,7 +161,9 @@ func (c *ClusterResourceBindingController) removeOrphanWorks(ctx context.Context
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (c *ClusterResourceBindingController) SetupWithManager(mgr controllerruntime.Manager) error { func (c *ClusterResourceBindingController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha2.ClusterResourceBinding{}). return controllerruntime.NewControllerManagedBy(mgr).
Named(ClusterResourceBindingControllerName).
For(&workv1alpha2.ClusterResourceBinding{}).
Watches(&policyv1alpha1.ClusterOverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())). Watches(&policyv1alpha1.ClusterOverridePolicy{}, handler.EnqueueRequestsFromMapFunc(c.newOverridePolicyFunc())).
WithEventFilter(predicate.GenerationChangedPredicate{}). WithEventFilter(predicate.GenerationChangedPredicate{}).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}). WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).

View File

@ -50,7 +50,7 @@ import (
) )
const ( const (
// CertRotationControllerName is the controller name that will be used when reporting events. // CertRotationControllerName is the controller name that will be used when reporting events and metrics.
CertRotationControllerName = "cert-rotation-controller" CertRotationControllerName = "cert-rotation-controller"
// SignerName defines the signer name for csr, 'kubernetes.io/kube-apiserver-client-kubelet' can sign the csr automatically // SignerName defines the signer name for csr, 'kubernetes.io/kube-apiserver-client-kubelet' can sign the csr automatically
@ -129,6 +129,7 @@ func (c *CertRotationController) Reconcile(ctx context.Context, req controllerru
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (c *CertRotationController) SetupWithManager(mgr controllerruntime.Manager) error { func (c *CertRotationController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(CertRotationControllerName).
For(&clusterv1alpha1.Cluster{}, builder.WithPredicates(c.PredicateFunc)). For(&clusterv1alpha1.Cluster{}, builder.WithPredicates(c.PredicateFunc)).
WithEventFilter(predicate.GenerationChangedPredicate{}). WithEventFilter(predicate.GenerationChangedPredicate{}).
WithOptions(controller.Options{ WithOptions(controller.Options{

View File

@ -51,7 +51,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "cluster-controller" ControllerName = "cluster-controller"
// MonitorRetrySleepTime is the amount of time the cluster controller that should // MonitorRetrySleepTime is the amount of time the cluster controller that should
// sleep between retrying cluster health updates. // sleep between retrying cluster health updates.
@ -215,7 +215,7 @@ func (c *Controller) Start(ctx context.Context) error {
func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error { func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error {
c.clusterHealthMap = newClusterHealthMap() c.clusterHealthMap = newClusterHealthMap()
return utilerrors.NewAggregate([]error{ return utilerrors.NewAggregate([]error{
controllerruntime.NewControllerManagedBy(mgr).For(&clusterv1alpha1.Cluster{}).Complete(c), controllerruntime.NewControllerManagedBy(mgr).Named(ControllerName).For(&clusterv1alpha1.Cluster{}).Complete(c),
mgr.Add(c), mgr.Add(c),
}) })
} }

View File

@ -39,7 +39,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/helper" "github.com/karmada-io/karmada/pkg/util/helper"
) )
// TaintManagerName is the controller name that will be used for taint management. // TaintManagerName is the controller name that will be used when reporting events and metrics.
const TaintManagerName = "taint-manager" const TaintManagerName = "taint-manager"
// NoExecuteTaintManager listens to Taint/Toleration changes and is responsible for removing objects // NoExecuteTaintManager listens to Taint/Toleration changes and is responsible for removing objects
@ -291,7 +291,7 @@ func (tc *NoExecuteTaintManager) needEviction(clusterName string, annotations ma
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (tc *NoExecuteTaintManager) SetupWithManager(mgr controllerruntime.Manager) error { func (tc *NoExecuteTaintManager) SetupWithManager(mgr controllerruntime.Manager) error {
return utilerrors.NewAggregate([]error{ return utilerrors.NewAggregate([]error{
controllerruntime.NewControllerManagedBy(mgr).For(&clusterv1alpha1.Cluster{}).Complete(tc), controllerruntime.NewControllerManagedBy(mgr).Named(TaintManagerName).For(&clusterv1alpha1.Cluster{}).Complete(tc),
mgr.Add(tc), mgr.Add(tc),
}) })
} }

View File

@ -39,7 +39,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "cronfederatedhpa-controller" ControllerName = "cronfederatedhpa-controller"
) )
@ -118,6 +118,7 @@ func (c *CronFHPAController) Reconcile(ctx context.Context, req controllerruntim
func (c *CronFHPAController) SetupWithManager(mgr controllerruntime.Manager) error { func (c *CronFHPAController) SetupWithManager(mgr controllerruntime.Manager) error {
c.CronHandler = NewCronHandler(mgr.GetClient(), mgr.GetEventRecorderFor(ControllerName)) c.CronHandler = NewCronHandler(mgr.GetClient(), mgr.GetEventRecorderFor(ControllerName))
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&autoscalingv1alpha1.CronFederatedHPA{}). For(&autoscalingv1alpha1.CronFederatedHPA{}).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}). WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
WithEventFilter(predicate.GenerationChangedPredicate{}). WithEventFilter(predicate.GenerationChangedPredicate{}).

View File

@ -37,7 +37,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "deployment-replicas-syncer" ControllerName = "deployment-replicas-syncer"
waitDeploymentStatusInterval = 1 * time.Second waitDeploymentStatusInterval = 1 * time.Second

View File

@ -53,7 +53,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "execution-controller" ControllerName = "execution-controller"
// WorkSuspendDispatchingConditionMessage is the condition and event message when dispatching is suspended. // WorkSuspendDispatchingConditionMessage is the condition and event message when dispatching is suspended.
WorkSuspendDispatchingConditionMessage = "Work dispatching is in a suspended state." WorkSuspendDispatchingConditionMessage = "Work dispatching is in a suspended state."
@ -133,6 +133,7 @@ func (c *Controller) Reconcile(ctx context.Context, req controllerruntime.Reques
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error { func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&workv1alpha1.Work{}, builder.WithPredicates(c.PredicateFunc)). For(&workv1alpha1.Work{}, builder.WithPredicates(c.PredicateFunc)).
WithEventFilter(predicate.GenerationChangedPredicate{}). WithEventFilter(predicate.GenerationChangedPredicate{}).
WithOptions(controller.Options{ WithOptions(controller.Options{

View File

@ -62,7 +62,7 @@ import (
// FederatedHPA-controller is borrowed from the HPA controller of Kubernetes. // FederatedHPA-controller is borrowed from the HPA controller of Kubernetes.
// The referenced code has been marked in the comment. // The referenced code has been marked in the comment.
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
const ControllerName = "federatedHPA-controller" const ControllerName = "federatedHPA-controller"
var ( var (
@ -128,6 +128,7 @@ func (c *FHPAController) SetupWithManager(mgr controllerruntime.Manager) error {
c.hpaSelectors = selectors.NewBiMultimap() c.hpaSelectors = selectors.NewBiMultimap()
c.monitor = monitor.New() c.monitor = monitor.New()
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&autoscalingv1alpha1.FederatedHPA{}). For(&autoscalingv1alpha1.FederatedHPA{}).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}). WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
WithEventFilter(predicate.GenerationChangedPredicate{}). WithEventFilter(predicate.GenerationChangedPredicate{}).

View File

@ -48,7 +48,7 @@ import (
) )
const ( const (
// StatusControllerName is the controller name that will be used when reporting events. // StatusControllerName is the controller name that will be used when reporting events and metrics.
StatusControllerName = "federated-resource-quota-status-controller" StatusControllerName = "federated-resource-quota-status-controller"
) )
@ -129,6 +129,7 @@ func (c *StatusController) SetupWithManager(mgr controllerruntime.Manager) error
}, },
}) })
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(StatusControllerName).
For(&policyv1alpha1.FederatedResourceQuota{}). For(&policyv1alpha1.FederatedResourceQuota{}).
Watches(&workv1alpha1.Work{}, handler.EnqueueRequestsFromMapFunc(fn), workPredicate). Watches(&workv1alpha1.Work{}, handler.EnqueueRequestsFromMapFunc(fn), workPredicate).
Complete(c) Complete(c)

View File

@ -44,7 +44,7 @@ import (
) )
const ( const (
// SyncControllerName is the controller name that will be used when reporting events. // SyncControllerName is the controller name that will be used when reporting events and metrics.
SyncControllerName = "federated-resource-quota-sync-controller" SyncControllerName = "federated-resource-quota-sync-controller"
) )
@ -129,6 +129,7 @@ func (c *SyncController) SetupWithManager(mgr controllerruntime.Manager) error {
}) })
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(SyncControllerName).
For(&policyv1alpha1.FederatedResourceQuota{}). For(&policyv1alpha1.FederatedResourceQuota{}).
Watches(&clusterv1alpha1.Cluster{}, handler.EnqueueRequestsFromMapFunc(fn), clusterPredicate). Watches(&clusterv1alpha1.Cluster{}, handler.EnqueueRequestsFromMapFunc(fn), clusterPredicate).
Complete(c) Complete(c)

View File

@ -37,7 +37,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/helper" "github.com/karmada-io/karmada/pkg/util/helper"
) )
// CRBGracefulEvictionControllerName is the controller name that will be used when reporting events. // CRBGracefulEvictionControllerName is the controller name that will be used when reporting events and metrics.
const CRBGracefulEvictionControllerName = "cluster-resource-binding-graceful-eviction-controller" const CRBGracefulEvictionControllerName = "cluster-resource-binding-graceful-eviction-controller"
// CRBGracefulEvictionController is to sync ClusterResourceBinding.spec.gracefulEvictionTasks. // CRBGracefulEvictionController is to sync ClusterResourceBinding.spec.gracefulEvictionTasks.
@ -125,6 +125,7 @@ func (c *CRBGracefulEvictionController) SetupWithManager(mgr controllerruntime.M
} }
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(CRBGracefulEvictionControllerName).
For(&workv1alpha2.ClusterResourceBinding{}, builder.WithPredicates(clusterResourceBindingPredicateFn)). For(&workv1alpha2.ClusterResourceBinding{}, builder.WithPredicates(clusterResourceBindingPredicateFn)).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}). WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
Complete(c) Complete(c)

View File

@ -37,7 +37,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/helper" "github.com/karmada-io/karmada/pkg/util/helper"
) )
// RBGracefulEvictionControllerName is the controller name that will be used when reporting events. // RBGracefulEvictionControllerName is the controller name that will be used when reporting events and metrics.
const RBGracefulEvictionControllerName = "resource-binding-graceful-eviction-controller" const RBGracefulEvictionControllerName = "resource-binding-graceful-eviction-controller"
// RBGracefulEvictionController is to sync ResourceBinding.spec.gracefulEvictionTasks. // RBGracefulEvictionController is to sync ResourceBinding.spec.gracefulEvictionTasks.
@ -125,6 +125,7 @@ func (c *RBGracefulEvictionController) SetupWithManager(mgr controllerruntime.Ma
} }
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(RBGracefulEvictionControllerName).
For(&workv1alpha2.ResourceBinding{}, builder.WithPredicates(resourceBindingPredicateFn)). For(&workv1alpha2.ResourceBinding{}, builder.WithPredicates(resourceBindingPredicateFn)).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}). WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).
Complete(c) Complete(c)

View File

@ -29,7 +29,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "hpa-scale-target-marker" ControllerName = "hpa-scale-target-marker"
// scaleTargetWorkerNum is the async Worker number // scaleTargetWorkerNum is the async Worker number
scaleTargetWorkerNum = 1 scaleTargetWorkerNum = 1

View File

@ -40,7 +40,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/names" "github.com/karmada-io/karmada/pkg/util/names"
) )
// EndpointSliceControllerName is the controller name that will be used when reporting events. // EndpointSliceControllerName is the controller name that will be used when reporting events and metrics.
const EndpointSliceControllerName = "endpointslice-controller" const EndpointSliceControllerName = "endpointslice-controller"
// EndpointSliceController is to collect EndpointSlice which reported by member cluster from executionNamespace to serviceexport namespace. // EndpointSliceController is to collect EndpointSlice which reported by member cluster from executionNamespace to serviceexport namespace.
@ -115,7 +115,10 @@ func (c *EndpointSliceController) SetupWithManager(mgr controllerruntime.Manager
return false return false
}, },
} }
return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha1.Work{}, builder.WithPredicates(serviceImportPredicateFun)).Complete(c) return controllerruntime.NewControllerManagedBy(mgr).
Named(EndpointSliceControllerName).
For(&workv1alpha1.Work{}, builder.WithPredicates(serviceImportPredicateFun)).
Complete(c)
} }
func (c *EndpointSliceController) collectEndpointSliceFromWork(ctx context.Context, work *workv1alpha1.Work) error { func (c *EndpointSliceController) collectEndpointSliceFromWork(ctx context.Context, work *workv1alpha1.Work) error {

View File

@ -55,7 +55,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/names" "github.com/karmada-io/karmada/pkg/util/names"
) )
// ServiceExportControllerName is the controller name that will be used when reporting events. // ServiceExportControllerName is the controller name that will be used when reporting events and metrics.
const ServiceExportControllerName = "service-export-controller" const ServiceExportControllerName = "service-export-controller"
// ServiceExportController is to sync ServiceExport and report EndpointSlices of exported service to control-plane. // ServiceExportController is to sync ServiceExport and report EndpointSlices of exported service to control-plane.
@ -131,7 +131,7 @@ func (c *ServiceExportController) Reconcile(ctx context.Context, req controllerr
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (c *ServiceExportController) SetupWithManager(mgr controllerruntime.Manager) error { func (c *ServiceExportController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha1.Work{}, builder.WithPredicates(c.PredicateFunc)).Complete(c) return controllerruntime.NewControllerManagedBy(mgr).Named(ServiceExportControllerName).For(&workv1alpha1.Work{}, builder.WithPredicates(c.PredicateFunc)).Complete(c)
} }
// RunWorkQueue initializes worker and run it, worker will process resource asynchronously. // RunWorkQueue initializes worker and run it, worker will process resource asynchronously.

View File

@ -35,7 +35,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/names" "github.com/karmada-io/karmada/pkg/util/names"
) )
// ServiceImportControllerName is the controller name that will be used when reporting events. // ServiceImportControllerName is the controller name that will be used when reporting events and metrics.
const ServiceImportControllerName = "service-import-controller" const ServiceImportControllerName = "service-import-controller"
// ServiceImportController is to sync derived service from ServiceImport. // ServiceImportController is to sync derived service from ServiceImport.
@ -71,7 +71,10 @@ func (c *ServiceImportController) Reconcile(ctx context.Context, req controllerr
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (c *ServiceImportController) SetupWithManager(mgr controllerruntime.Manager) error { func (c *ServiceImportController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr).For(&mcsv1alpha1.ServiceImport{}).Complete(c) return controllerruntime.NewControllerManagedBy(mgr).
Named(ServiceImportControllerName).
For(&mcsv1alpha1.ServiceImport{}).
Complete(c)
} }
func (c *ServiceImportController) deleteDerivedService(ctx context.Context, svcImport types.NamespacedName) (controllerruntime.Result, error) { func (c *ServiceImportController) deleteDerivedService(ctx context.Context, svcImport types.NamespacedName) (controllerruntime.Result, error) {

View File

@ -74,6 +74,9 @@ var (
multiClusterServiceGVK = networkingv1alpha1.SchemeGroupVersion.WithKind("MultiClusterService") multiClusterServiceGVK = networkingv1alpha1.SchemeGroupVersion.WithKind("MultiClusterService")
) )
// EndpointSliceCollectControllerName is the controller name that will be used when reporting events and metrics.
const EndpointSliceCollectControllerName = "endpointslice-collect-controller"
// 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.
func (c *EndpointSliceCollectController) Reconcile(ctx context.Context, req controllerruntime.Request) (controllerruntime.Result, error) { func (c *EndpointSliceCollectController) Reconcile(ctx context.Context, req controllerruntime.Request) (controllerruntime.Result, error) {
klog.V(4).Infof("Reconciling Work %s", req.NamespacedName.String()) klog.V(4).Infof("Reconciling Work %s", req.NamespacedName.String())
@ -115,6 +118,7 @@ func (c *EndpointSliceCollectController) Reconcile(ctx context.Context, req cont
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (c *EndpointSliceCollectController) SetupWithManager(mgr controllerruntime.Manager) error { func (c *EndpointSliceCollectController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(EndpointSliceCollectControllerName).
For(&workv1alpha1.Work{}, builder.WithPredicates(c.PredicateFunc)).Complete(c) For(&workv1alpha1.Work{}, builder.WithPredicates(c.PredicateFunc)).Complete(c)
} }

View File

@ -49,7 +49,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/names" "github.com/karmada-io/karmada/pkg/util/names"
) )
// EndpointsliceDispatchControllerName is the controller name that will be used when reporting events. // EndpointsliceDispatchControllerName is the controller name that will be used when reporting events and metrics.
const EndpointsliceDispatchControllerName = "endpointslice-dispatch-controller" const EndpointsliceDispatchControllerName = "endpointslice-dispatch-controller"
// EndpointsliceDispatchController will reconcile a MultiClusterService object // EndpointsliceDispatchController will reconcile a MultiClusterService object
@ -160,7 +160,9 @@ func (c *EndpointsliceDispatchController) SetupWithManager(mgr controllerruntime
return false return false
}, },
} }
return controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha1.Work{}, builder.WithPredicates(workPredicateFun)). return controllerruntime.NewControllerManagedBy(mgr).
Named(EndpointsliceDispatchControllerName).
For(&workv1alpha1.Work{}, builder.WithPredicates(workPredicateFun)).
Watches(&networkingv1alpha1.MultiClusterService{}, handler.EnqueueRequestsFromMapFunc(c.newMultiClusterServiceFunc())). Watches(&networkingv1alpha1.MultiClusterService{}, handler.EnqueueRequestsFromMapFunc(c.newMultiClusterServiceFunc())).
Watches(&clusterv1alpha1.Cluster{}, handler.EnqueueRequestsFromMapFunc(c.newClusterFunc())). Watches(&clusterv1alpha1.Cluster{}, handler.EnqueueRequestsFromMapFunc(c.newClusterFunc())).
Complete(c) Complete(c)

View File

@ -54,7 +54,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/names" "github.com/karmada-io/karmada/pkg/util/names"
) )
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
const ControllerName = "multiclusterservice-controller" const ControllerName = "multiclusterservice-controller"
// MCSController is to sync MultiClusterService. // MCSController is to sync MultiClusterService.
@ -600,6 +600,7 @@ func (c *MCSController) SetupWithManager(mgr controllerruntime.Manager) error {
}) })
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&networkingv1alpha1.MultiClusterService{}, builder.WithPredicates(mcsPredicateFunc)). For(&networkingv1alpha1.MultiClusterService{}, builder.WithPredicates(mcsPredicateFunc)).
Watches(&corev1.Service{}, handler.EnqueueRequestsFromMapFunc(svcMapFunc), builder.WithPredicates(svcPredicateFunc)). Watches(&corev1.Service{}, handler.EnqueueRequestsFromMapFunc(svcMapFunc), builder.WithPredicates(svcPredicateFunc)).
Watches(&clusterv1alpha1.Cluster{}, handler.EnqueueRequestsFromMapFunc(c.clusterMapFunc())). Watches(&clusterv1alpha1.Cluster{}, handler.EnqueueRequestsFromMapFunc(c.clusterMapFunc())).

View File

@ -48,7 +48,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "namespace-sync-controller" ControllerName = "namespace-sync-controller"
) )
@ -273,6 +273,7 @@ func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error {
}) })
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&corev1.Namespace{}). For(&corev1.Namespace{}).
Watches(&clusterv1alpha1.Cluster{}, Watches(&clusterv1alpha1.Cluster{},
handler.EnqueueRequestsFromMapFunc(clusterNamespaceFn), handler.EnqueueRequestsFromMapFunc(clusterNamespaceFn),

View File

@ -34,7 +34,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/helper" "github.com/karmada-io/karmada/pkg/util/helper"
) )
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
const ControllerName = "remedy-controller" const ControllerName = "remedy-controller"
// RemedyController is to sync Cluster resource, according to the cluster status // RemedyController is to sync Cluster resource, according to the cluster status

View File

@ -58,7 +58,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "cluster-status-controller" ControllerName = "cluster-status-controller"
clusterReady = "ClusterReady" clusterReady = "ClusterReady"
clusterHealthy = "cluster is healthy and ready to accept workloads" clusterHealthy = "cluster is healthy and ready to accept workloads"
@ -171,6 +171,7 @@ func (c *ClusterStatusController) SetupWithManager(mgr controllerruntime.Manager
failureThreshold: c.ClusterFailureThreshold.Duration, failureThreshold: c.ClusterFailureThreshold.Duration,
} }
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&clusterv1alpha1.Cluster{}, builder.WithPredicates(c.PredicateFunc)). For(&clusterv1alpha1.Cluster{}, builder.WithPredicates(c.PredicateFunc)).
WithOptions(controller.Options{ WithOptions(controller.Options{
RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions), RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions),

View File

@ -39,7 +39,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/helper" "github.com/karmada-io/karmada/pkg/util/helper"
) )
// CRBStatusControllerName is the controller name that will be used when reporting events. // CRBStatusControllerName is the controller name that will be used when reporting events and metrics.
const CRBStatusControllerName = "cluster-resource-binding-status-controller" const CRBStatusControllerName = "cluster-resource-binding-status-controller"
// CRBStatusController is to sync status of ClusterResourceBinding // CRBStatusController is to sync status of ClusterResourceBinding
@ -101,7 +101,8 @@ func (c *CRBStatusController) SetupWithManager(mgr controllerruntime.Manager) er
return requests return requests
}) })
return controllerruntime.NewControllerManagedBy(mgr).Named("clusterResourceBinding_status_controller"). return controllerruntime.NewControllerManagedBy(mgr).
Named(CRBStatusControllerName).
For(&workv1alpha2.ClusterResourceBinding{}, bindingPredicateFn). For(&workv1alpha2.ClusterResourceBinding{}, bindingPredicateFn).
Watches(&workv1alpha1.Work{}, handler.EnqueueRequestsFromMapFunc(workMapFunc), workPredicateFn). Watches(&workv1alpha1.Work{}, handler.EnqueueRequestsFromMapFunc(workMapFunc), workPredicateFn).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}). WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).

View File

@ -39,7 +39,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/helper" "github.com/karmada-io/karmada/pkg/util/helper"
) )
// RBStatusControllerName is the controller name that will be used when reporting events. // RBStatusControllerName is the controller name that will be used when reporting events and metrics.
const RBStatusControllerName = "resource-binding-status-controller" const RBStatusControllerName = "resource-binding-status-controller"
// RBStatusController is to sync status of ResourceBinding // RBStatusController is to sync status of ResourceBinding
@ -103,7 +103,8 @@ func (c *RBStatusController) SetupWithManager(mgr controllerruntime.Manager) err
return requests return requests
}) })
return controllerruntime.NewControllerManagedBy(mgr).Named("resourceBinding_status_controller"). return controllerruntime.NewControllerManagedBy(mgr).
Named(RBStatusControllerName).
For(&workv1alpha2.ResourceBinding{}, bindingPredicateFn). For(&workv1alpha2.ResourceBinding{}, bindingPredicateFn).
Watches(&workv1alpha1.Work{}, handler.EnqueueRequestsFromMapFunc(workMapFunc), workPredicateFn). Watches(&workv1alpha1.Work{}, handler.EnqueueRequestsFromMapFunc(workMapFunc), workPredicateFn).
WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}). WithOptions(controller.Options{RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions)}).

View File

@ -55,7 +55,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/restmapper" "github.com/karmada-io/karmada/pkg/util/restmapper"
) )
// WorkStatusControllerName is the controller name that will be used when reporting events. // WorkStatusControllerName is the controller name that will be used when reporting events and metrics.
const WorkStatusControllerName = "work-status-controller" const WorkStatusControllerName = "work-status-controller"
// WorkStatusController is to sync status of Work. // WorkStatusController is to sync status of Work.
@ -546,6 +546,7 @@ func (c *WorkStatusController) getSingleClusterManager(cluster *clusterv1alpha1.
// SetupWithManager creates a controller and register to controller manager. // SetupWithManager creates a controller and register to controller manager.
func (c *WorkStatusController) SetupWithManager(mgr controllerruntime.Manager) error { func (c *WorkStatusController) SetupWithManager(mgr controllerruntime.Manager) error {
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(WorkStatusControllerName).
For(&workv1alpha1.Work{}, builder.WithPredicates(c.PredicateFunc)). For(&workv1alpha1.Work{}, builder.WithPredicates(c.PredicateFunc)).
WithOptions(controller.Options{ WithOptions(controller.Options{
RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions), RateLimiter: ratelimiterflag.DefaultControllerRateLimiter(c.RateLimiterOptions),

View File

@ -44,7 +44,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "unified-auth-controller" ControllerName = "unified-auth-controller"
karmadaImpersonatorName = "karmada-impersonator" karmadaImpersonatorName = "karmada-impersonator"
@ -255,6 +255,7 @@ func (c *Controller) SetupWithManager(mgr controllerruntime.Manager) error {
} }
return controllerruntime.NewControllerManagedBy(mgr). return controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&clusterv1alpha1.Cluster{}, builder.WithPredicates(clusterPredicateFunc)). For(&clusterv1alpha1.Cluster{}, builder.WithPredicates(clusterPredicateFunc)).
Watches(&rbacv1.ClusterRole{}, handler.EnqueueRequestsFromMapFunc(c.newClusterRoleMapFunc())). Watches(&rbacv1.ClusterRole{}, handler.EnqueueRequestsFromMapFunc(c.newClusterRoleMapFunc())).
Watches(&rbacv1.ClusterRoleBinding{}, handler.EnqueueRequestsFromMapFunc(c.newClusterRoleBindingMapFunc())). Watches(&rbacv1.ClusterRoleBinding{}, handler.EnqueueRequestsFromMapFunc(c.newClusterRoleBindingMapFunc())).

View File

@ -40,7 +40,7 @@ import (
) )
const ( const (
// ControllerName is the controller name that will be used when reporting events. // ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "workload-rebalancer" ControllerName = "workload-rebalancer"
) )

View File

@ -61,6 +61,11 @@ import (
"github.com/karmada-io/karmada/pkg/util/restmapper" "github.com/karmada-io/karmada/pkg/util/restmapper"
) )
const (
// ControllerName is the controller name that will be used when reporting events and metrics.
ControllerName = "dependencies-distributor"
)
// well-know labels // well-know labels
const ( const (
// dependedByLabelKeyPrefix is added to the attached binding, it is the // dependedByLabelKeyPrefix is added to the attached binding, it is the
@ -622,7 +627,9 @@ func (d *DependenciesDistributor) SetupWithManager(mgr controllerruntime.Manager
d.genericEvent = make(chan event.TypedGenericEvent[*workv1alpha2.ResourceBinding]) d.genericEvent = make(chan event.TypedGenericEvent[*workv1alpha2.ResourceBinding])
return utilerrors.NewAggregate([]error{ return utilerrors.NewAggregate([]error{
mgr.Add(d), mgr.Add(d),
controllerruntime.NewControllerManagedBy(mgr).For(&workv1alpha2.ResourceBinding{}). controllerruntime.NewControllerManagedBy(mgr).
Named(ControllerName).
For(&workv1alpha2.ResourceBinding{}).
WithEventFilter(predicate.Funcs{ WithEventFilter(predicate.Funcs{
CreateFunc: func(event event.CreateEvent) bool { CreateFunc: func(event event.CreateEvent) bool {
bindingObject := event.Object.(*workv1alpha2.ResourceBinding) bindingObject := event.Object.(*workv1alpha2.ResourceBinding)