Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(providers/kubernetes): Added QPS and Burst tweaks for client-side throttling #179

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/providers/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
core_v1 "k8s.io/api/core/v1"

"github.com/acouvreur/sablier/app/instance"
providerConfig "github.com/acouvreur/sablier/config"
log "github.com/sirupsen/logrus"
autoscalingv1 "k8s.io/api/autoscaling/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
Expand Down Expand Up @@ -60,12 +62,18 @@ type KubernetesProvider struct {
Client kubernetes.Interface
}

func NewKubernetesProvider() (*KubernetesProvider, error) {
config, err := rest.InClusterConfig()
func NewKubernetesProvider(providerConfig providerConfig.Kubernetes) (*KubernetesProvider, error) {
kubeclientConfig, err := rest.InClusterConfig()

kubeclientConfig.QPS = providerConfig.QPS
kubeclientConfig.Burst = providerConfig.Burst

log.Debug(fmt.Sprintf("Provider configuration: QPS=%v, Burst=%v", kubeclientConfig.QPS, kubeclientConfig.Burst))

if err != nil {
return nil, err
}
client, err := kubernetes.NewForConfig(config)
client, err := kubernetes.NewForConfig(kubeclientConfig)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion app/providers/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewProvider(config config.Provider) (Provider, error) {
case config.Name == "docker":
return NewDockerClassicProvider()
case config.Name == "kubernetes":
return NewKubernetesProvider()
return NewKubernetesProvider(config.Kubernetes)
}
return nil, fmt.Errorf("unimplemented provider %s", config.Name)
}
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ It provides an integrations with multiple reverse proxies and different loading
// Provider flags
startCmd.Flags().StringVar(&conf.Provider.Name, "provider.name", "docker", fmt.Sprintf("Provider to use to manage containers %v", config.GetProviders()))
viper.BindPFlag("provider.name", startCmd.Flags().Lookup("provider.name"))
startCmd.Flags().Float32Var(&conf.Provider.Kubernetes.QPS, "provider.kubernetes.qps", 5, fmt.Sprintf("QPS limit for K8S API access client-side throttling"))
viper.BindPFlag("provider.kubernetes.qps", startCmd.Flags().Lookup("provider.kubernetes.qps"))
startCmd.Flags().IntVar(&conf.Provider.Kubernetes.Burst, "provider.kubernetes.burst", 10, fmt.Sprintf("Maximum burst for K8S API acees client-side throttling"))
viper.BindPFlag("provider.kubernetes.burst", startCmd.Flags().Lookup("provider.kubernetes.burst"))
// Server flags
startCmd.Flags().IntVar(&conf.Server.Port, "server.port", 10000, "The server port to use")
viper.BindPFlag("server.port", startCmd.Flags().Lookup("server.port"))
Expand Down
2 changes: 2 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func TestPrecedence(t *testing.T) {
"--configFile", filepath.Join(testDir, "testdata", "config.yml"),
"start",
"--provider.name", "cli",
"--provider.kubernetes.qps", "256",
"--provider.kubernetes.burst", "512",
"--server.port", "3333",
"--server.base-path", "/cli/",
"--storage.file", "/tmp/cli.json",
Expand Down
2 changes: 2 additions & 0 deletions cmd/testdata/config.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PROVIDER_NAME=envvar
PROVIDER_KUBERNETES_QPS=16
PROVIDER_KUBERNETES_BURST=32
SERVER_PORT=2222
SERVER_BASE_PATH=/envvar/
STORAGE_FILE=/tmp/envvar.json
Expand Down
3 changes: 3 additions & 0 deletions cmd/testdata/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
provider:
name: configfile
kubernetes:
qps: 64
burst: 128
server:
port: 1111
base-path: /configfile/
Expand Down
6 changes: 5 additions & 1 deletion cmd/testdata/config_cli_wanted.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"File": "/tmp/cli.json"
},
"Provider": {
"Name": "cli"
"Name": "cli",
"Kubernetes": {
"QPS": 256,
"Burst": 512
}
},
"Sessions": {
"DefaultDuration": 10800000000000,
Expand Down
6 changes: 5 additions & 1 deletion cmd/testdata/config_env_wanted.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"File": "/tmp/envvar.json"
},
"Provider": {
"Name": "envvar"
"Name": "envvar",
"Kubernetes": {
"QPS": 16,
"Burst": 32
}
},
"Sessions": {
"DefaultDuration": 7200000000000,
Expand Down
6 changes: 5 additions & 1 deletion cmd/testdata/config_yaml_wanted.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"File": "/tmp/configfile.json"
},
"Provider": {
"Name": "configfile"
"Name": "configfile",
"Kubernetes": {
"QPS": 64,
"Burst": 128
}
},
"Sessions": {
"DefaultDuration": 3600000000000,
Expand Down
14 changes: 13 additions & 1 deletion config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ import (
// Provider holds the provider description
// It can be either docker, swarm or kubernetes
type Provider struct {
Name string `mapstructure:"NAME" yaml:"provider,omitempty"`
Name string `mapstructure:"NAME" yaml:"provider,omitempty"`
Kubernetes Kubernetes
}

type Kubernetes struct {
//QPS limit for K8S API access client-side throttle
QPS float32 `mapstructure:"QPS" yaml:"QPS" default:"5"`
//Maximum burst for client-side throttle
Burst int `mapstructure:"BURST" yaml:"Burst" default:"10"`
}

var providers = []string{"docker", "swarm", "kubernetes"}

func NewProviderConfig() Provider {
return Provider{
Name: "docker",
Kubernetes: Kubernetes{
QPS: 5,
Burst: 10,
},
}
}

Expand Down
Loading