From b0a33779017b1bc0e8afa1187fb59f3c69578d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Wed, 29 May 2024 17:21:54 +0200 Subject: [PATCH 1/3] feat(k8s-client): tweak default config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon Mañes --- pkg/k8s/k8s.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index 78102753..96fd3af2 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -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 + + // CustomBurst is the Burst to use for the Kubernetes client, DefaultBurst: 10. + CustomBurst = 200 ) type Client struct { @@ -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 } // precompile the regular expression to avoid recompiling it on every function call From 76d74b09e82491e04ff3c207b5de10d620ed461f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Fri, 31 May 2024 09:40:03 +0200 Subject: [PATCH 2/3] fix(comments): refactor func MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon Mañes --- pkg/k8s/k8s.go | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index 96fd3af2..04fef244 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -108,22 +108,14 @@ func fileExists(path string) bool { // 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) { +func getClusterConfig() (config *rest.Config, err error) { if isClusterEnvironment() { - config, err := rest.InClusterConfig() - if err != nil { - return nil, err - } - - // Increase QPS and Burst settings - config.QPS = CustomQPS - config.Burst = CustomBurst - return config, nil + config, err = rest.InClusterConfig() + } else { + // build the configuration from the kubeconfig file + kubeconfig := filepath.Join(os.Getenv("HOME"), ".kube", "config") + config, err = clientcmd.BuildConfigFromFlags("", kubeconfig) } - - // build the configuration from the kubeconfig file - kubeconfig := filepath.Join(os.Getenv("HOME"), ".kube", "config") - config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) if err != nil { return nil, err } From 3a89961ee303c8134be7eefdfc0b865002026a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Fri, 31 May 2024 10:45:14 +0200 Subject: [PATCH 3/3] fix(comments): add log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon Mañes --- pkg/k8s/k8s.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/k8s/k8s.go b/pkg/k8s/k8s.go index 04fef244..44d867e0 100644 --- a/pkg/k8s/k8s.go +++ b/pkg/k8s/k8s.go @@ -117,6 +117,7 @@ func getClusterConfig() (config *rest.Config, err error) { config, err = clientcmd.BuildConfigFromFlags("", kubeconfig) } if err != nil { + logrus.Errorf("Error getting kubernetes config: %v", err) return nil, err }