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

feat(k8s-client): tweak default config #399

Merged
merged 5 commits into from
Jun 3, 2024
Merged
Changes from 1 commit
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
30 changes: 28 additions & 2 deletions pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ const (

// waitRetry is the time to wait between retries for a readiness checking
waitRetry = 2 * time.Second

// CustomQPS is the QPS to use for the Kubernetes client, DefaultQPS: 5
CustomQPS = 100
tty47 marked this conversation as resolved.
Show resolved Hide resolved

// CustomBurst is the Burst to use for the Kubernetes client, DefaultBurst: 10.
CustomBurst = 200
)

type Client struct {
Expand Down Expand Up @@ -98,14 +104,34 @@ func fileExists(path string) bool {
}

// getClusterConfig returns the appropriate Kubernetes cluster configuration.
// If the program is running in a Kubernetes cluster, it returns the in-cluster configuration.
// Otherwise, it returns the configuration from the kubeconfig file.
//
// The QPS and Burst settings are increased to allow for higher throughput and concurrency.
func getClusterConfig() (*rest.Config, error) {
if isClusterEnvironment() {
return rest.InClusterConfig()
config, err := rest.InClusterConfig()
if err != nil {
return nil, err
}

// Increase QPS and Burst settings
config.QPS = CustomQPS
config.Burst = CustomBurst
return config, nil
}

// build the configuration from the kubeconfig file
kubeconfig := filepath.Join(os.Getenv("HOME"), ".kube", "config")
return clientcmd.BuildConfigFromFlags("", kubeconfig)
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return nil, err
}

// Increase QPS and Burst settings
config.QPS = CustomQPS
config.Burst = CustomBurst
return config, nil
MSevey marked this conversation as resolved.
Show resolved Hide resolved
}

// precompile the regular expression to avoid recompiling it on every function call
Expand Down
Loading