Skip to content

Commit ba34136

Browse files
committed
✨ Add flags for configuring rate limits
All the controllers have built-in rate limits. They throttle themselves if they hit this limit. So far it has not been possible to configure these limits. This commit adds flags to the controllers for setting both the QPS and the burst for the rate limits. The default remains the same as before (20 QPS, 30 burst). New flags (for each controller, including CAPD): --kube-api-qps --kube-api-burst Also adds .devcontainer to .gitignore.
1 parent a25723c commit ba34136

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ tmp
8989

9090
# asdf (not a typo! ;) used to manage multiple versions of tools
9191
.tool-versions
92+
93+
# Development container configurations (https://containers.dev/)
94+
.devcontainer

bootstrap/kubeadm/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ var (
8484
profilerAddress string
8585
kubeadmConfigConcurrency int
8686
syncPeriod time.Duration
87+
restConfigQPS float32
88+
restConfigBurst int
8789
webhookPort int
8890
webhookCertDir string
8991
healthAddr string
@@ -123,6 +125,12 @@ func InitFlags(fs *pflag.FlagSet) {
123125
fs.DurationVar(&syncPeriod, "sync-period", 10*time.Minute,
124126
"The minimum interval at which watched resources are reconciled (e.g. 15m)")
125127

128+
fs.Float32Var(&restConfigQPS, "kube-api-qps", 20,
129+
"Maximum queries per second from the controller client to the Kubernetes API server. Defaults to 20")
130+
131+
fs.IntVar(&restConfigBurst, "kube-api-burst", 30,
132+
"Maximum number of queries that should be allowed in one burst from the controller client to the Kubernetes API server. Default 30")
133+
126134
fs.DurationVar(&tokenTTL, "bootstrap-token-ttl", kubeadmbootstrapcontrollers.DefaultTokenTTL,
127135
"The amount of time the bootstrap token will be valid")
128136

@@ -167,6 +175,8 @@ func main() {
167175
}
168176

169177
restConfig := ctrl.GetConfigOrDie()
178+
restConfig.QPS = restConfigQPS
179+
restConfig.Burst = restConfigBurst
170180
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent("cluster-api-kubeadm-bootstrap-manager")
171181

172182
tlsOptionOverrides, err := flags.GetTLSOptionOverrideFuncs(tlsOptions)

controlplane/kubeadm/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ var (
8989
profilerAddress string
9090
kubeadmControlPlaneConcurrency int
9191
syncPeriod time.Duration
92+
restConfigQPS float32
93+
restConfigBurst int
9294
webhookPort int
9395
webhookCertDir string
9496
healthAddr string
@@ -129,6 +131,12 @@ func InitFlags(fs *pflag.FlagSet) {
129131
fs.DurationVar(&syncPeriod, "sync-period", 10*time.Minute,
130132
"The minimum interval at which watched resources are reconciled (e.g. 15m)")
131133

134+
fs.Float32Var(&restConfigQPS, "kube-api-qps", 20,
135+
"Maximum queries per second from the controller client to the Kubernetes API server. Defaults to 20")
136+
137+
fs.IntVar(&restConfigBurst, "kube-api-burst", 30,
138+
"Maximum number of queries that should be allowed in one burst from the controller client to the Kubernetes API server. Default 30")
139+
132140
fs.StringVar(&watchFilterValue, "watch-filter", "",
133141
fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel))
134142

@@ -176,6 +184,8 @@ func main() {
176184
}
177185

178186
restConfig := ctrl.GetConfigOrDie()
187+
restConfig.QPS = restConfigQPS
188+
restConfig.Burst = restConfigBurst
179189
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent("cluster-api-kubeadm-control-plane-manager")
180190

181191
tlsOptionOverrides, err := flags.GetTLSOptionOverrideFuncs(tlsOptions)

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ var (
9999
clusterResourceSetConcurrency int
100100
machineHealthCheckConcurrency int
101101
syncPeriod time.Duration
102+
restConfigQPS float32
103+
restConfigBurst int
102104
webhookPort int
103105
webhookCertDir string
104106
healthAddr string
@@ -192,6 +194,12 @@ func InitFlags(fs *pflag.FlagSet) {
192194
fs.DurationVar(&syncPeriod, "sync-period", 10*time.Minute,
193195
"The minimum interval at which watched resources are reconciled (e.g. 15m)")
194196

197+
fs.Float32Var(&restConfigQPS, "kube-api-qps", 20,
198+
"Maximum queries per second from the controller client to the Kubernetes API server. Defaults to 20")
199+
200+
fs.IntVar(&restConfigBurst, "kube-api-burst", 30,
201+
"Maximum number of queries that should be allowed in one burst from the controller client to the Kubernetes API server. Default 30")
202+
195203
fs.IntVar(&webhookPort, "webhook-port", 9443,
196204
"Webhook Server port")
197205

@@ -231,6 +239,8 @@ func main() {
231239
}
232240

233241
restConfig := ctrl.GetConfigOrDie()
242+
restConfig.QPS = restConfigQPS
243+
restConfig.Burst = restConfigBurst
234244
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent("cluster-api-controller-manager")
235245

236246
minVer := version.MinimumKubernetesVersion

test/infrastructure/docker/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ var (
6767
profilerAddress string
6868
syncPeriod time.Duration
6969
concurrency int
70+
restConfigQPS float32
71+
restConfigBurst int
7072
healthAddr string
7173
webhookPort int
7274
webhookCertDir string
@@ -99,6 +101,10 @@ func initFlags(fs *pflag.FlagSet) {
99101
"Bind address to expose the pprof profiler (e.g. localhost:6060)")
100102
fs.DurationVar(&syncPeriod, "sync-period", 10*time.Minute,
101103
"The minimum interval at which watched resources are reconciled (e.g. 15m)")
104+
fs.Float32Var(&restConfigQPS, "kube-api-qps", 20,
105+
"Maximum queries per second from the controller client to the Kubernetes API server. Defaults to 20")
106+
fs.IntVar(&restConfigBurst, "kube-api-burst", 30,
107+
"Maximum number of queries that should be allowed in one burst from the controller client to the Kubernetes API server. Default 30")
102108
fs.StringVar(&healthAddr, "health-addr", ":9440",
103109
"The address the health endpoint binds to.")
104110
fs.IntVar(&webhookPort, "webhook-port", 9443,
@@ -139,6 +145,8 @@ func main() {
139145
}
140146

141147
restConfig := ctrl.GetConfigOrDie()
148+
restConfig.QPS = restConfigQPS
149+
restConfig.Burst = restConfigBurst
142150
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent("cluster-api-docker-controller-manager")
143151
ctrlOptions := ctrl.Options{
144152
Scheme: myscheme,

0 commit comments

Comments
 (0)