Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct Helm actions using Helm env helpers #4515

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -76,6 +78,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also include a link to the request to make the retrying roundtripper public: helm/helm#13052.

If that's public, we could even consider to use this in k0s's kube clients as well 🤔
And we could add this depending whether we use etcd or not.

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 @@ -85,6 +95,7 @@ func (hc *Commands) getActionCfg(namespace string) (*action.Configuration, error
CacheDir: ptr.To(hc.helmCacheDir),
Namespace: ptr.To(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
Loading