Skip to content

Commit ab40409

Browse files
committed
⚠️ Config: Disable client-side ratelimiter by default
Sig-Apimachinery recommends [disabling the client-side ratelimiter][0] and rely on API priority and fairness instead for any [Kubernetes version >= 1.22][1]. Update our config getters to do that. 0: https://kubernetes.slack.com/archives/C0EG7JC6T/p1680889646346859?thread_ts=1680791299.631439&cid=C0EG7JC6T 1: https://kubernetes.slack.com/archives/C0EG7JC6T/p1680892224956789?thread_ts=1680791299.631439&cid=C0EG7JC6T
1 parent 5e8256e commit ab40409

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

alias.go

+6
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,19 @@ var (
7777
// If --kubeconfig is set, will use the kubeconfig file at that location. Otherwise will assume running
7878
// in cluster and use the cluster provided kubeconfig.
7979
//
80+
// The returned `*rest.Config` has client-side ratelimting disabled as we can rely on API priority and
81+
// fairness. Set its QPS to a value equal or bigger than 0 to re-enable it.
82+
//
8083
// Will log an error and exit if there is an error creating the rest.Config.
8184
GetConfigOrDie = config.GetConfigOrDie
8285

8386
// GetConfig creates a *rest.Config for talking to a Kubernetes apiserver.
8487
// If --kubeconfig is set, will use the kubeconfig file at that location. Otherwise will assume running
8588
// in cluster and use the cluster provided kubeconfig.
8689
//
90+
// The returned `*rest.Config` has client-side ratelimting disabled as we can rely on API priority and
91+
// fairness. Set its QPS to a value equal or bigger than 0 to re-enable it.
92+
//
8793
// Config precedence
8894
//
8995
// * --kubeconfig flag pointing at a file

pkg/client/config/config.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ func RegisterFlags(fs *flag.FlagSet) {
6161
// If --kubeconfig is set, will use the kubeconfig file at that location. Otherwise will assume running
6262
// in cluster and use the cluster provided kubeconfig.
6363
//
64+
// The returned `*rest.Config` has client-side ratelimting disabled as we can rely on API priority and
65+
// fairness. Set its QPS to a value equal or bigger than 0 to re-enable it.
66+
//
6467
// It also applies saner defaults for QPS and burst based on the Kubernetes
6568
// controller manager defaults (20 QPS, 30 burst)
6669
//
@@ -81,6 +84,9 @@ func GetConfig() (*rest.Config, error) {
8184
// If --kubeconfig is set, will use the kubeconfig file at that location. Otherwise will assume running
8285
// in cluster and use the cluster provided kubeconfig.
8386
//
87+
// The returned `*rest.Config` has client-side ratelimting disabled as we can rely on API priority and
88+
// fairness. Set its QPS to a value equal or bigger than 0 to re-enable it.
89+
//
8490
// It also applies saner defaults for QPS and burst based on the Kubernetes
8591
// controller manager defaults (20 QPS, 30 burst)
8692
//
@@ -99,10 +105,9 @@ func GetConfigWithContext(context string) (*rest.Config, error) {
99105
return nil, err
100106
}
101107
if cfg.QPS == 0.0 {
102-
cfg.QPS = 20.0
103-
}
104-
if cfg.Burst == 0 {
105-
cfg.Burst = 30
108+
// Disable client-side ratelimer by default, we can rely on
109+
// API priority and fairness
110+
cfg.QPS = -1
106111
}
107112
return cfg, nil
108113
}
@@ -170,6 +175,9 @@ func loadConfigWithContext(apiServerURL string, loader clientcmd.ClientConfigLoa
170175
// If --kubeconfig is set, will use the kubeconfig file at that location. Otherwise will assume running
171176
// in cluster and use the cluster provided kubeconfig.
172177
//
178+
// The returned `*rest.Config` has client-side ratelimting disabled as we can rely on API priority and
179+
// fairness. Set its QPS to a value equal or bigger than 0 to re-enable it.
180+
//
173181
// Will log an error and exit if there is an error creating the rest.Config.
174182
func GetConfigOrDie() *rest.Config {
175183
config, err := GetConfig()

pkg/client/config/config_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var _ = Describe("Config", func() {
7272
cfg, err := GetConfigWithContext(tc.context)
7373
Expect(err).NotTo(HaveOccurred())
7474
Expect(cfg.Host).To(Equal(tc.wantHost))
75+
Expect(cfg.QPS).To(Equal(float32(-1)))
7576
})
7677
}
7778
}
@@ -82,8 +83,8 @@ var _ = Describe("Config", func() {
8283
Expect(err).NotTo(HaveOccurred())
8384

8485
cfg, err := GetConfigWithContext("")
85-
Expect(cfg).To(BeNil())
8686
Expect(err).To(HaveOccurred())
87+
Expect(cfg).To(BeNil())
8788
})
8889
})
8990

0 commit comments

Comments
 (0)