From 453a8b1ee37b362f3e1abc30851a36846f7a7974 Mon Sep 17 00:00:00 2001 From: Andy Lo-A-Foe Date: Sun, 29 Jan 2023 18:14:04 +0100 Subject: [PATCH] Implement burst_limit parameter #1011 Adds the ability to configure the burst_limit of the client-go client used by Helm. If your cluster has a lot of CRDs e.g. when Crossplane is installed, the DiscoveryClient performs many API calls potentially triggering client-side rate limiting. Increasing the burst_limit reduces this throttling, significantly speeding up install or update actions, sometimes by a factor 10. Co-authored-by: Marco Franssen --- helm/provider.go | 6 ++++++ helm/structure_kubeconfig.go | 7 +++++-- website/docs/index.html.markdown | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/helm/provider.go b/helm/provider.go index 714fd9f18f..a80b74f6fc 100644 --- a/helm/provider.go +++ b/helm/provider.go @@ -101,6 +101,12 @@ func Provider() *schema.Provider { } }, }, + "burst_limit": { + Type: schema.TypeInt, + Optional: true, + Default: 100, + Description: "Helm burst limit. Increase this if you have a cluster with many CRDs", + }, "kubernetes": { Type: schema.TypeList, MaxItems: 1, diff --git a/helm/structure_kubeconfig.go b/helm/structure_kubeconfig.go index 826c747a05..f86f74f37a 100644 --- a/helm/structure_kubeconfig.go +++ b/helm/structure_kubeconfig.go @@ -25,6 +25,8 @@ import ( type KubeConfig struct { ClientConfig clientcmd.ClientConfig + Burst int + sync.Mutex } @@ -44,7 +46,7 @@ func (k *KubeConfig) ToDiscoveryClient() (discovery.CachedDiscoveryInterface, er // The more groups you have, the more discovery requests you need to make. // given 25 groups (our groups + a few custom resources) with one-ish version each, discovery needs to make 50 requests // double it just so we don't end up here again for a while. This config is only used for discovery. - config.Burst = 100 + config.Burst = k.Burst return memcached.NewMemCacheClient(discovery.NewDiscoveryClientForConfigOrDie(config)), nil } @@ -186,6 +188,7 @@ func newKubeConfig(configData *schema.ResourceData, namespace *string) (*KubeCon if namespace != nil { overrides.Context.Namespace = *namespace } + burstLimit := configData.Get("burst_limit").(int) client := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loader, overrides) if client == nil { @@ -194,5 +197,5 @@ func newKubeConfig(configData *schema.ResourceData, namespace *string) (*KubeCon } log.Printf("[INFO] Successfully initialized kubernetes config") - return &KubeConfig{ClientConfig: client}, nil + return &KubeConfig{ClientConfig: client, Burst: burstLimit}, nil } diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 38b89329a8..73534a5164 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -150,6 +150,7 @@ The following arguments are supported: * `repository_cache` - (Optional) The path to the file containing cached repository indexes. Defaults to `HELM_REPOSITORY_CACHE` env if it is set, otherwise uses the default path set by helm. * `helm_driver` - (Optional) "The backend storage driver. Valid values are: `configmap`, `secret`, `memory`, `sql`. Defaults to `secret`. Note: Regarding the sql driver, as of helm v3.2.0 SQL support exists only for the postgres dialect. The connection string can be configured by setting the `HELM_DRIVER_SQL_CONNECTION_STRING` environment variable e.g. `HELM_DRIVER_SQL_CONNECTION_STRING=postgres://username:password@host/dbname` more info [here](https://pkg.go.dev/github.com/lib/pq). +* `burst_limit` - (Optional) The helm burst limit to use. Set this value higher if your cluster has many CRDs. Default: `100` * `kubernetes` - Kubernetes configuration block. * `registry` - Private OCI registry configuration block. Can be specified multiple times.