Skip to content

Commit

Permalink
Merge pull request #4519 from k0sproject/backport-4515-to-release-1.29
Browse files Browse the repository at this point in the history
[Backport release-1.29] Construct Helm actions using Helm env helpers
  • Loading branch information
twz123 authored May 29, 2024
2 parents 28b998c + 74ec7ac commit 473ff86
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 @@ -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{
Expand All @@ -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 {
Expand Down

0 comments on commit 473ff86

Please sign in to comment.