From 5dd1f64d725c197ece236d627cfc0257983c1f01 Mon Sep 17 00:00:00 2001 From: Jussi Nummelin Date: Wed, 29 May 2024 14:23:26 +0300 Subject: [PATCH] Construct Helm actions using Helm env helpers This way we get the retrying round-tripper setup and Helm now retries some known transient errors such as the etcd leader change. Fixes #3758 Signed-off-by: Jussi Nummelin (cherry picked from commit 11da64fe116848aaf24ed43ee7e5eab6138a7373) --- pkg/helm/helm.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/helm/helm.go b/pkg/helm/helm.go index 59e273a4fd14..4aac2ec10b40 100644 --- a/pkg/helm/helm.go +++ b/pkg/helm/helm.go @@ -18,6 +18,7 @@ package helm import ( "context" + "errors" "fmt" "os" "path/filepath" @@ -28,6 +29,7 @@ import ( "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/chart/loader" + "helm.sh/helm/v3/pkg/cli" "helm.sh/helm/v3/pkg/downloader" "helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/release" @@ -75,6 +77,14 @@ func NewCommands(k0sVars *config.CfgVars) *Commands { } func (hc *Commands) getActionCfg(namespace string) (*action.Configuration, error) { + // Construct new helm env so we get the retrying roundtripper etc. setup + // See https://github.com/helm/helm/pull/11426/commits/b5378b3a5dd435e5c364ac0cfa717112ad686bd0 + helmEnv := cli.New() + helmFlags, ok := helmEnv.RESTClientGetter().(*genericclioptions.ConfigFlags) + if !ok { + return nil, errors.New("failed to construct Helm REST client") + } + insecure := false var impersonateGroup []string cfg := &genericclioptions.ConfigFlags{ @@ -84,6 +94,7 @@ func (hc *Commands) getActionCfg(namespace string) (*action.Configuration, error CacheDir: stringptr(hc.helmCacheDir), Namespace: stringptr(namespace), ImpersonateGroup: &impersonateGroup, + WrapConfigFn: helmFlags.WrapConfigFn, // This contains the retrying round tripper } actionConfig := &action.Configuration{} if err := actionConfig.Init(cfg, namespace, "secret", logFn); err != nil {