diff --git a/cmd/agent/app/agent.go b/cmd/agent/app/agent.go index 75026dadbd6b..521d77a89112 100644 --- a/cmd/agent/app/agent.go +++ b/cmd/agent/app/agent.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "os" - "time" "github.com/spf13/cobra" corev1 "k8s.io/api/core/v1" @@ -116,11 +115,9 @@ func run(ctx context.Context, karmadaConfig karmadactl.KarmadaConfig, opts *opti return err } - // TODO(Garrybest): add resyncPeriod to options - resyncPeriod := time.Duration(0) controllerManager, err := controllerruntime.NewManager(controlPlaneRestConfig, controllerruntime.Options{ Scheme: gclient.NewSchema(), - SyncPeriod: &resyncPeriod, + SyncPeriod: &opts.ResyncPeriod.Duration, Namespace: executionSpace, LeaderElection: opts.LeaderElection.LeaderElect, LeaderElectionID: fmt.Sprintf("karmada-agent-%s", opts.ClusterName), diff --git a/cmd/agent/app/options/options.go b/cmd/agent/app/options/options.go index b72b5fbded02..b492974a87ce 100644 --- a/cmd/agent/app/options/options.go +++ b/cmd/agent/app/options/options.go @@ -47,6 +47,9 @@ type Options struct { KubeAPIBurst int ClusterCacheSyncTimeout metav1.Duration + // ResyncPeriod is the base frequency the informers are resynced. + // Defaults to 0. + ResyncPeriod metav1.Duration // ClusterAPIEndpoint holds the apiEndpoint of the cluster. ClusterAPIEndpoint string @@ -93,4 +96,5 @@ func (o *Options) AddFlags(fs *pflag.FlagSet, allControllers []string) { fs.DurationVar(&o.ClusterCacheSyncTimeout.Duration, "cluster-cache-sync-timeout", util.CacheSyncTimeout, "Timeout period waiting for cluster cache to sync.") fs.StringVar(&o.ClusterAPIEndpoint, "cluster-api-endpoint", o.ClusterAPIEndpoint, "APIEndpoint of the cluster.") fs.StringVar(&o.ProxyServerAddress, "proxy-server-address", o.ProxyServerAddress, "Address of the proxy server that is used to proxy to the cluster.") + fs.DurationVar(&o.ResyncPeriod.Duration, "resync-period", 0, "Base frequency the informers are resynced.") } diff --git a/cmd/controller-manager/app/controllermanager.go b/cmd/controller-manager/app/controllermanager.go index 64c961a7933a..c1cbf4ff0f8b 100644 --- a/cmd/controller-manager/app/controllermanager.go +++ b/cmd/controller-manager/app/controllermanager.go @@ -6,7 +6,6 @@ import ( "net" "os" "strconv" - "time" "github.com/spf13/cobra" "k8s.io/client-go/discovery" @@ -75,11 +74,9 @@ func Run(ctx context.Context, opts *options.Options) error { panic(err) } config.QPS, config.Burst = opts.KubeAPIQPS, opts.KubeAPIBurst - // TODO(Garrybest): add resyncPeriod to options - resyncPeriod := time.Duration(0) controllerManager, err := controllerruntime.NewManager(config, controllerruntime.Options{ Scheme: gclient.NewSchema(), - SyncPeriod: &resyncPeriod, + SyncPeriod: &opts.ResyncPeriod.Duration, LeaderElection: opts.LeaderElection.LeaderElect, LeaderElectionID: opts.LeaderElection.ResourceName, LeaderElectionNamespace: opts.LeaderElection.ResourceNamespace, diff --git a/cmd/controller-manager/app/options/options.go b/cmd/controller-manager/app/options/options.go index d10a27ad07cd..cab8c7f5c91c 100644 --- a/cmd/controller-manager/app/options/options.go +++ b/cmd/controller-manager/app/options/options.go @@ -71,6 +71,9 @@ type Options struct { KubeAPIBurst int // ClusterCacheSyncTimeout is the timeout period waiting for cluster cache to sync ClusterCacheSyncTimeout metav1.Duration + // ResyncPeriod is the base frequency the informers are resynced. + // Defaults to 0. + ResyncPeriod metav1.Duration } // NewOptions builds an empty options. @@ -122,4 +125,5 @@ func (o *Options) AddFlags(flags *pflag.FlagSet, allControllers []string) { 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.") flags.DurationVar(&o.ClusterCacheSyncTimeout.Duration, "cluster-cache-sync-timeout", util.CacheSyncTimeout, "Timeout period waiting for cluster cache to sync.") + flags.DurationVar(&o.ResyncPeriod.Duration, "resync-period", 0, "Base frequency the informers are resynced.") }