Optimize the controllers flag
Signed-off-by: Xinzhao Xu <z2d@jifangcheng.com>
This commit is contained in:
parent
43d75741e8
commit
1e9c24d667
|
|
@ -6,7 +6,6 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"k8s.io/client-go/discovery"
|
||||
|
|
@ -149,9 +148,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
|
||||
setupClusterAPIClusterDetector(mgr, opts, stopChan)
|
||||
|
||||
controllers := strings.Split(opts.Controllers, ",")
|
||||
|
||||
if IsControllerEnabled("cluster", controllers) {
|
||||
if opts.IsControllerEnabled("cluster") {
|
||||
clusterController := &cluster.Controller{
|
||||
Client: mgr.GetClient(),
|
||||
EventRecorder: mgr.GetEventRecorderFor(cluster.ControllerName),
|
||||
|
|
@ -164,7 +161,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
}
|
||||
}
|
||||
|
||||
if IsControllerEnabled("clusterStatus", controllers) {
|
||||
if opts.IsControllerEnabled("clusterStatus") {
|
||||
clusterPredicateFunc := predicate.Funcs{
|
||||
CreateFunc: func(createEvent event.CreateEvent) bool {
|
||||
obj := createEvent.Object.(*clusterv1alpha1.Cluster)
|
||||
|
|
@ -202,7 +199,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
}
|
||||
}
|
||||
|
||||
if IsControllerEnabled("hpa", controllers) {
|
||||
if opts.IsControllerEnabled("hpa") {
|
||||
hpaController := &hpa.HorizontalPodAutoscalerController{
|
||||
Client: mgr.GetClient(),
|
||||
DynamicClient: dynamicClientSet,
|
||||
|
|
@ -215,7 +212,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
}
|
||||
}
|
||||
|
||||
if IsControllerEnabled("binding", controllers) {
|
||||
if opts.IsControllerEnabled("binding") {
|
||||
bindingController := &binding.ResourceBindingController{
|
||||
Client: mgr.GetClient(),
|
||||
DynamicClient: dynamicClientSet,
|
||||
|
|
@ -241,7 +238,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
}
|
||||
}
|
||||
|
||||
if IsControllerEnabled("execution", controllers) {
|
||||
if opts.IsControllerEnabled("execution") {
|
||||
executionController := &execution.Controller{
|
||||
Client: mgr.GetClient(),
|
||||
EventRecorder: mgr.GetEventRecorderFor(execution.ControllerName),
|
||||
|
|
@ -255,7 +252,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
}
|
||||
}
|
||||
|
||||
if IsControllerEnabled("workStatus", controllers) {
|
||||
if opts.IsControllerEnabled("workStatus") {
|
||||
workStatusController := &status.WorkStatusController{
|
||||
Client: mgr.GetClient(),
|
||||
EventRecorder: mgr.GetEventRecorderFor(status.WorkStatusControllerName),
|
||||
|
|
@ -273,7 +270,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
}
|
||||
}
|
||||
|
||||
if IsControllerEnabled("namespace", controllers) {
|
||||
if opts.IsControllerEnabled("namespace") {
|
||||
namespaceSyncController := &namespace.Controller{
|
||||
Client: mgr.GetClient(),
|
||||
EventRecorder: mgr.GetEventRecorderFor(namespace.ControllerName),
|
||||
|
|
@ -284,7 +281,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
}
|
||||
}
|
||||
|
||||
if IsControllerEnabled("serviceExport", controllers) {
|
||||
if opts.IsControllerEnabled("serviceExport") {
|
||||
serviceExportController := &mcs.ServiceExportController{
|
||||
Client: mgr.GetClient(),
|
||||
EventRecorder: mgr.GetEventRecorderFor(mcs.ServiceExportControllerName),
|
||||
|
|
@ -301,7 +298,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
}
|
||||
}
|
||||
|
||||
if IsControllerEnabled("endpointSlice", controllers) {
|
||||
if opts.IsControllerEnabled("endpointSlice") {
|
||||
endpointSliceController := &mcs.EndpointSliceController{
|
||||
Client: mgr.GetClient(),
|
||||
EventRecorder: mgr.GetEventRecorderFor(mcs.EndpointSliceControllerName),
|
||||
|
|
@ -311,7 +308,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop
|
|||
}
|
||||
}
|
||||
|
||||
if IsControllerEnabled("serviceImport", controllers) {
|
||||
if opts.IsControllerEnabled("serviceImport") {
|
||||
serviceImportController := &mcs.ServiceImportController{
|
||||
Client: mgr.GetClient(),
|
||||
EventRecorder: mgr.GetEventRecorderFor(mcs.ServiceImportControllerName),
|
||||
|
|
@ -360,20 +357,3 @@ func setupClusterAPIClusterDetector(mgr controllerruntime.Manager, opts *options
|
|||
|
||||
klog.Infof("Success to setup cluster-api cluster detector")
|
||||
}
|
||||
|
||||
// IsControllerEnabled check if a specified controller enabled or not.
|
||||
func IsControllerEnabled(name string, controllers []string) bool {
|
||||
hasStar := false
|
||||
for _, ctrl := range controllers {
|
||||
if ctrl == name {
|
||||
return true
|
||||
}
|
||||
if ctrl == "-"+name {
|
||||
return false
|
||||
}
|
||||
if ctrl == "*" {
|
||||
hasStar = true
|
||||
}
|
||||
}
|
||||
return hasStar
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const (
|
|||
|
||||
// Options contains everything necessary to create and run controller-manager.
|
||||
type Options struct {
|
||||
Controllers string
|
||||
Controllers []string
|
||||
|
||||
LeaderElection componentbaseconfig.LeaderElectionConfiguration
|
||||
// BindAddress is the IP address on which to listen for the --secure-port port.
|
||||
|
|
@ -78,7 +78,7 @@ func NewOptions() *Options {
|
|||
|
||||
// AddFlags adds flags to the specified FlagSet.
|
||||
func (o *Options) AddFlags(flags *pflag.FlagSet) {
|
||||
flags.StringVar(&o.Controllers, "controllers", "*", "A list of controllers to enable. '*' enables all on-by-default controllers, 'foo' enables the controller named 'foo', '-foo' disables the controller named 'foo'. All controllers: cluster, clusterStatus, hpa, binding, execution, workStatus, namespace, serviceExport, endpointSlice, serviceImport.")
|
||||
flags.StringSliceVar(&o.Controllers, "controllers", []string{"*"}, "A list of controllers to enable. '*' enables all on-by-default controllers, 'foo' enables the controller named 'foo', '-foo' disables the controller named 'foo'. All controllers: cluster, clusterStatus, hpa, binding, execution, workStatus, namespace, serviceExport, endpointSlice, serviceImport.")
|
||||
flags.StringVar(&o.BindAddress, "bind-address", defaultBindAddress,
|
||||
"The IP address on which to listen for the --secure-port port.")
|
||||
flags.IntVar(&o.SecurePort, "secure-port", defaultPort,
|
||||
|
|
@ -110,3 +110,20 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
|
|||
flags.Float32Var(&o.KubeAPIQPS, "kube-api-qps", 40.0, "QPS to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.")
|
||||
flags.IntVar(&o.KubeAPIBurst, "kube-api-burst", 60, "Burst to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.")
|
||||
}
|
||||
|
||||
// IsControllerEnabled check if a specified controller enabled or not.
|
||||
func (o *Options) IsControllerEnabled(name string) bool {
|
||||
hasStar := false
|
||||
for _, ctrl := range o.Controllers {
|
||||
if ctrl == name {
|
||||
return true
|
||||
}
|
||||
if ctrl == "-"+name {
|
||||
return false
|
||||
}
|
||||
if ctrl == "*" {
|
||||
hasStar = true
|
||||
}
|
||||
}
|
||||
return hasStar
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue