Skip to content

Commit

Permalink
Add flags to allow tuning k8s client throttling.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkh52 committed Apr 2, 2021
1 parent 63f2c4d commit e8a0110
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ type ProxyRunOptions struct {
authenticationAudience string
// Path to kubeconfig (used by kubernetes client)
kubeconfigPath string
// Client maximum QPS.
kubeconfigQps float32
// Client maximum burst for throttle.
kubeconfigBurst int

// Proxy strategies used by the server.
// NOTE the order of the strategies matters. e.g., for list
Expand Down Expand Up @@ -154,6 +158,8 @@ func (o *ProxyRunOptions) Flags() *pflag.FlagSet {
flags.StringVar(&o.agentNamespace, "agent-namespace", o.agentNamespace, "Expected agent's namespace during agent authentication (used with agent-service-account, authentication-audience, kubeconfig).")
flags.StringVar(&o.agentServiceAccount, "agent-service-account", o.agentServiceAccount, "Expected agent's service account during agent authentication (used with agent-namespace, authentication-audience, kubeconfig).")
flags.StringVar(&o.kubeconfigPath, "kubeconfig", o.kubeconfigPath, "absolute path to the kubeconfig file (used with agent-namespace, agent-service-account, authentication-audience).")
flags.Float32Var(&o.kubeconfigQps, "kubeconfig-qps", o.kubeconfigQps, "Maximum client QPS (used with authentication).")
flags.IntVar(&o.kubeconfigBurst, "kubeconfig-burst", o.kubeconfigBurst, "Maximum client burst (used with authentication).")
flags.StringVar(&o.authenticationAudience, "authentication-audience", o.authenticationAudience, "Expected agent's token authentication audience (used with agent-namespace, agent-service-account, kubeconfig).")
flags.StringVar(&o.proxyStrategies, "proxy-strategies", o.proxyStrategies, "The list of proxy strategies used by the server to pick a backend/tunnel, available strategies are: default, destHost.")
return flags
Expand Down Expand Up @@ -182,6 +188,8 @@ func (o *ProxyRunOptions) Print() {
klog.V(1).Infof("AgentServiceAccount set to %q.\n", o.agentServiceAccount)
klog.V(1).Infof("AuthenticationAudience set to %q.\n", o.authenticationAudience)
klog.V(1).Infof("KubeconfigPath set to %q.\n", o.kubeconfigPath)
klog.V(1).Infof("KubeconfigQps set to %f.\n", o.kubeconfigQps)
klog.V(1).Infof("KubeconfigBurst set to %d.\n", o.kubeconfigBurst)
klog.V(1).Infof("ProxyStrategies set to %q.\n", o.proxyStrategies)
}

Expand Down Expand Up @@ -277,7 +285,7 @@ func (o *ProxyRunOptions) Validate() error {
}

// validate agent authentication params
// all 4 parametes must be empty or must have value (except kubeconfigPath that might be empty)
// all 4 parameters must be empty or must have value (except kubeconfigPath that might be empty)
if o.agentNamespace != "" || o.agentServiceAccount != "" || o.authenticationAudience != "" || o.kubeconfigPath != "" {
if o.clusterCaCert != "" {
return fmt.Errorf("clusterCaCert can not be used when service account authentication is enabled")
Expand Down Expand Up @@ -337,6 +345,8 @@ func newProxyRunOptions() *ProxyRunOptions {
agentNamespace: "",
agentServiceAccount: "",
kubeconfigPath: "",
kubeconfigQps: 0,
kubeconfigBurst: 0,
authenticationAudience: "",
proxyStrategies: "default",
}
Expand Down Expand Up @@ -375,6 +385,14 @@ func (p *Proxy) run(o *ProxyRunOptions) error {
return fmt.Errorf("failed to load kubernetes client config: %v", err)
}

if o.kubeconfigQps != 0 {
klog.V(1).Infoln("Setting k8s client QPS: %v", o.kubeconfigQps)
config.QPS = o.kubeconfigQps
}
if o.kubeconfigBurst != 0 {
klog.V(1).Infoln("Setting k8s client Burst: %v", o.kubeconfigBurst)
config.Burst = o.kubeconfigBurst
}
k8sClient, err = kubernetes.NewForConfig(config)
if err != nil {
return fmt.Errorf("failed to create kubernetes clientset: %v", err)
Expand Down

0 comments on commit e8a0110

Please sign in to comment.