Skip to content

Commit fc5ec8d

Browse files
committed
chore: config for qps/burst
1 parent 05a9dcc commit fc5ec8d

File tree

4 files changed

+94
-8
lines changed

4 files changed

+94
-8
lines changed

cmd/main.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ func main() {
123123
// TODO(jreese) validate the config
124124

125125
cfg := ctrl.GetConfigOrDie()
126-
cfg.QPS = 50
127-
cfg.Burst = 100
126+
serverConfig.ControlPlaneClient.ApplyTo(cfg)
128127

129128
deploymentCluster, err := cluster.New(cfg, func(o *cluster.Options) {
130129
o.Scheme = scheme
@@ -191,8 +190,7 @@ func main() {
191190
setupLog.Error(err, "unable to load control plane kubeconfig")
192191
os.Exit(1)
193192
}
194-
downstreamRestConfig.QPS = 50
195-
downstreamRestConfig.Burst = 100
193+
serverConfig.DownstreamClient.ApplyTo(downstreamRestConfig)
196194

197195
downstreamCluster, err := cluster.New(downstreamRestConfig, func(o *cluster.Options) {
198196
o.Scheme = scheme
@@ -445,15 +443,13 @@ func initializeClusterDiscovery(
445443
if err != nil {
446444
return nil, nil, fmt.Errorf("unable to get discovery rest config: %w", err)
447445
}
448-
discoveryRestConfig.QPS = 50
449-
discoveryRestConfig.Burst = 100
446+
serverConfig.ProjectClient.ApplyTo(discoveryRestConfig)
450447

451448
projectRestConfig, err := serverConfig.Discovery.ProjectRestConfig()
452449
if err != nil {
453450
return nil, nil, fmt.Errorf("unable to get project rest config: %w", err)
454451
}
455-
projectRestConfig.QPS = 50
456-
projectRestConfig.Burst = 100
452+
serverConfig.ProjectClient.ApplyTo(projectRestConfig)
457453

458454
discoveryManager, err := manager.New(discoveryRestConfig, manager.Options{
459455
Client: client.Options{

internal/config/config.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,57 @@ type NetworkServicesOperator struct {
6060

6161
// DomainRegistration controls RDAP/WHOIS refresh behavior for Domain status.registration
6262
DomainRegistration DomainRegistrationConfig `json:"domainRegistration"`
63+
64+
// ControlPlaneClient configures the Kubernetes client connection to the
65+
// control plane where the operator runs (leader election, multicluster
66+
// coordination).
67+
ControlPlaneClient ClientConnectionConfig `json:"controlPlaneClient,omitempty"`
68+
69+
// DownstreamClient configures the Kubernetes client connection to the
70+
// downstream cluster where Gateways, HTTPRoutes, Certificates, and other
71+
// data-plane resources are materialized.
72+
DownstreamClient ClientConnectionConfig `json:"downstreamClient,omitempty"`
73+
74+
// ProjectClient configures the Kubernetes client connection used for both
75+
// project discovery and per-project cluster connections.
76+
ProjectClient ClientConnectionConfig `json:"projectClient,omitempty"`
77+
}
78+
79+
// +k8s:deepcopy-gen=true
80+
81+
// ClientConnectionConfig holds settings that control how the operator connects
82+
// to a Kubernetes API server.
83+
type ClientConnectionConfig struct {
84+
// QPS is the maximum sustained queries per second before client-side
85+
// throttling kicks in.
86+
//
87+
// +default=50
88+
QPS float32 `json:"qps,omitempty"`
89+
90+
// Burst is the maximum burst size for throttle. Requests above QPS but
91+
// below Burst are allowed immediately.
92+
//
93+
// +default=100
94+
Burst int `json:"burst,omitempty"`
95+
}
96+
97+
// ApplyTo applies the client connection settings to a rest.Config.
98+
func (c *ClientConnectionConfig) ApplyTo(cfg *rest.Config) {
99+
if c.QPS > 0 {
100+
cfg.QPS = c.QPS
101+
}
102+
if c.Burst > 0 {
103+
cfg.Burst = c.Burst
104+
}
105+
}
106+
107+
func SetDefaults_ClientConnectionConfig(obj *ClientConnectionConfig) {
108+
if obj.QPS == 0 {
109+
obj.QPS = 50
110+
}
111+
if obj.Burst == 0 {
112+
obj.Burst = 100
113+
}
63114
}
64115

65116
// +k8s:deepcopy-gen=true

internal/config/zz_generated.deepcopy.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/config/zz_generated.defaults.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)