update dependencies (#6267)
Signed-off-by: hongming <coder.scala@gmail.com>
(cherry picked from commit cfebd96a1f)
This commit is contained in:
106
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controller.go
generated
vendored
106
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controller.go
generated
vendored
@@ -25,17 +25,23 @@ import (
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"sigs.k8s.io/controller-runtime/pkg/handler"
|
||||
"sigs.k8s.io/controller-runtime/pkg/internal/controller"
|
||||
"sigs.k8s.io/controller-runtime/pkg/manager"
|
||||
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
||||
"sigs.k8s.io/controller-runtime/pkg/ratelimiter"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||
)
|
||||
|
||||
// Options are the arguments for creating a new Controller.
|
||||
type Options struct {
|
||||
type Options = TypedOptions[reconcile.Request]
|
||||
|
||||
// TypedOptions are the arguments for creating a new Controller.
|
||||
type TypedOptions[request comparable] struct {
|
||||
// SkipNameValidation allows skipping the name validation that ensures that every controller name is unique.
|
||||
// Unique controller names are important to get unique metrics and logs for a controller.
|
||||
// Defaults to the Controller.SkipNameValidation setting from the Manager if unset.
|
||||
// Defaults to false if Controller.SkipNameValidation setting from the Manager is also unset.
|
||||
SkipNameValidation *bool
|
||||
|
||||
// MaxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 1.
|
||||
MaxConcurrentReconciles int
|
||||
|
||||
@@ -45,6 +51,7 @@ type Options struct {
|
||||
|
||||
// RecoverPanic indicates whether the panic caused by reconcile should be recovered.
|
||||
// Defaults to the Controller.RecoverPanic setting from the Manager if unset.
|
||||
// Defaults to true if Controller.RecoverPanic setting from the Manager is also unset.
|
||||
RecoverPanic *bool
|
||||
|
||||
// NeedLeaderElection indicates whether the controller needs to use leader election.
|
||||
@@ -52,33 +59,43 @@ type Options struct {
|
||||
NeedLeaderElection *bool
|
||||
|
||||
// Reconciler reconciles an object
|
||||
Reconciler reconcile.Reconciler
|
||||
Reconciler reconcile.TypedReconciler[request]
|
||||
|
||||
// RateLimiter is used to limit how frequently requests may be queued.
|
||||
// Defaults to MaxOfRateLimiter which has both overall and per-item rate limiting.
|
||||
// The overall is a token bucket and the per-item is exponential.
|
||||
RateLimiter ratelimiter.RateLimiter
|
||||
RateLimiter workqueue.TypedRateLimiter[request]
|
||||
|
||||
// NewQueue constructs the queue for this controller once the controller is ready to start.
|
||||
// With NewQueue a custom queue implementation can be used, e.g. a priority queue to prioritize with which
|
||||
// priority/order objects are reconciled (e.g. to reconcile objects with changes first).
|
||||
// This is a func because the standard Kubernetes work queues start themselves immediately, which
|
||||
// leads to goroutine leaks if something calls controller.New repeatedly.
|
||||
// The NewQueue func gets the controller name and the RateLimiter option (defaulted if necessary) passed in.
|
||||
// NewQueue defaults to NewRateLimitingQueueWithConfig.
|
||||
//
|
||||
// NOTE: LOW LEVEL PRIMITIVE!
|
||||
// Only use a custom NewQueue if you know what you are doing.
|
||||
NewQueue func(controllerName string, rateLimiter workqueue.TypedRateLimiter[request]) workqueue.TypedRateLimitingInterface[request]
|
||||
|
||||
// LogConstructor is used to construct a logger used for this controller and passed
|
||||
// to each reconciliation via the context field.
|
||||
LogConstructor func(request *reconcile.Request) logr.Logger
|
||||
LogConstructor func(request *request) logr.Logger
|
||||
}
|
||||
|
||||
// Controller implements a Kubernetes API. A Controller manages a work queue fed reconcile.Requests
|
||||
// from source.Sources. Work is performed through the reconcile.Reconciler for each enqueued item.
|
||||
// Work typically is reads and writes Kubernetes objects to make the system state match the state specified
|
||||
// in the object Spec.
|
||||
type Controller interface {
|
||||
// Reconciler is called to reconcile an object by Namespace/Name
|
||||
reconcile.Reconciler
|
||||
type Controller = TypedController[reconcile.Request]
|
||||
|
||||
// Watch takes events provided by a Source and uses the EventHandler to
|
||||
// enqueue reconcile.Requests in response to the events.
|
||||
//
|
||||
// Watch may be provided one or more Predicates to filter events before
|
||||
// they are given to the EventHandler. Events will be passed to the
|
||||
// EventHandler if all provided Predicates evaluate to true.
|
||||
Watch(src source.Source, eventhandler handler.EventHandler, predicates ...predicate.Predicate) error
|
||||
// TypedController implements an API.
|
||||
type TypedController[request comparable] interface {
|
||||
// Reconciler is called to reconcile an object by Namespace/Name
|
||||
reconcile.TypedReconciler[request]
|
||||
|
||||
// Watch watches the provided Source.
|
||||
Watch(src source.TypedSource[request]) error
|
||||
|
||||
// Start starts the controller. Start blocks until the context is closed or a
|
||||
// controller has an error starting.
|
||||
@@ -90,8 +107,17 @@ type Controller interface {
|
||||
|
||||
// New returns a new Controller registered with the Manager. The Manager will ensure that shared Caches have
|
||||
// been synced before the Controller is Started.
|
||||
//
|
||||
// The name must be unique as it is used to identify the controller in metrics and logs.
|
||||
func New(name string, mgr manager.Manager, options Options) (Controller, error) {
|
||||
c, err := NewUnmanaged(name, mgr, options)
|
||||
return NewTyped(name, mgr, options)
|
||||
}
|
||||
|
||||
// NewTyped returns a new typed controller registered with the Manager,
|
||||
//
|
||||
// The name must be unique as it is used to identify the controller in metrics and logs.
|
||||
func NewTyped[request comparable](name string, mgr manager.Manager, options TypedOptions[request]) (TypedController[request], error) {
|
||||
c, err := NewTypedUnmanaged(name, mgr, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -102,7 +128,16 @@ func New(name string, mgr manager.Manager, options Options) (Controller, error)
|
||||
|
||||
// NewUnmanaged returns a new controller without adding it to the manager. The
|
||||
// caller is responsible for starting the returned controller.
|
||||
//
|
||||
// The name must be unique as it is used to identify the controller in metrics and logs.
|
||||
func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller, error) {
|
||||
return NewTypedUnmanaged(name, mgr, options)
|
||||
}
|
||||
|
||||
// NewTypedUnmanaged returns a new typed controller without adding it to the manager.
|
||||
//
|
||||
// The name must be unique as it is used to identify the controller in metrics and logs.
|
||||
func NewTypedUnmanaged[request comparable](name string, mgr manager.Manager, options TypedOptions[request]) (TypedController[request], error) {
|
||||
if options.Reconciler == nil {
|
||||
return nil, fmt.Errorf("must specify Reconciler")
|
||||
}
|
||||
@@ -111,13 +146,23 @@ func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller
|
||||
return nil, fmt.Errorf("must specify Name for Controller")
|
||||
}
|
||||
|
||||
if options.SkipNameValidation == nil {
|
||||
options.SkipNameValidation = mgr.GetControllerOptions().SkipNameValidation
|
||||
}
|
||||
|
||||
if options.SkipNameValidation == nil || !*options.SkipNameValidation {
|
||||
if err := checkName(name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if options.LogConstructor == nil {
|
||||
log := mgr.GetLogger().WithValues(
|
||||
"controller", name,
|
||||
)
|
||||
options.LogConstructor = func(req *reconcile.Request) logr.Logger {
|
||||
options.LogConstructor = func(in *request) logr.Logger {
|
||||
log := log
|
||||
if req != nil {
|
||||
if req, ok := any(in).(*reconcile.Request); ok && req != nil {
|
||||
log = log.WithValues(
|
||||
"object", klog.KRef(req.Namespace, req.Name),
|
||||
"namespace", req.Namespace, "name", req.Name,
|
||||
@@ -144,7 +189,15 @@ func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller
|
||||
}
|
||||
|
||||
if options.RateLimiter == nil {
|
||||
options.RateLimiter = workqueue.DefaultControllerRateLimiter()
|
||||
options.RateLimiter = workqueue.DefaultTypedControllerRateLimiter[request]()
|
||||
}
|
||||
|
||||
if options.NewQueue == nil {
|
||||
options.NewQueue = func(controllerName string, rateLimiter workqueue.TypedRateLimiter[request]) workqueue.TypedRateLimitingInterface[request] {
|
||||
return workqueue.NewTypedRateLimitingQueueWithConfig(rateLimiter, workqueue.TypedRateLimitingQueueConfig[request]{
|
||||
Name: controllerName,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if options.RecoverPanic == nil {
|
||||
@@ -156,13 +209,10 @@ func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller
|
||||
}
|
||||
|
||||
// Create controller with dependencies set
|
||||
return &controller.Controller{
|
||||
Do: options.Reconciler,
|
||||
MakeQueue: func() workqueue.RateLimitingInterface {
|
||||
return workqueue.NewRateLimitingQueueWithConfig(options.RateLimiter, workqueue.RateLimitingQueueConfig{
|
||||
Name: name,
|
||||
})
|
||||
},
|
||||
return &controller.Controller[request]{
|
||||
Do: options.Reconciler,
|
||||
RateLimiter: options.RateLimiter,
|
||||
NewQueue: options.NewQueue,
|
||||
MaxConcurrentReconciles: options.MaxConcurrentReconciles,
|
||||
CacheSyncTimeout: options.CacheSyncTimeout,
|
||||
Name: name,
|
||||
|
||||
Reference in New Issue
Block a user