Skip to content

Commit

Permalink
Construct Helm actions using Helm env helpers
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit 11da64f)
  • Loading branch information
jnummelin authored and github-actions[bot] committed May 29, 2024
1 parent e8df04b commit d880347
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package helm

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -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"
Expand Down Expand Up @@ -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{
Expand All @@ -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 {
Expand Down

0 comments on commit d880347

Please sign in to comment.