From d880347f35ce883e3bfde154cdaaf5ddb3d214f3 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 3dab809a2157..8aec49821b75 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" @@ -74,6 +76,14 @@ func NewCommands(k0sVars constant.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{ @@ -83,6 +93,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 {