Merge pull request #31048 from unguiculus/issue-12952

fix(v3 backport): Add timeout flag to repo add and update flags
dev-v3
George Jenkins 3 days ago committed by GitHub
commit 0111c25229
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -51,6 +51,7 @@ type repoAddOptions struct {
passCredentialsAll bool passCredentialsAll bool
forceUpdate bool forceUpdate bool
allowDeprecatedRepos bool allowDeprecatedRepos bool
timeout time.Duration
certFile string certFile string
keyFile string keyFile string
@ -99,6 +100,7 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
f.BoolVar(&o.insecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the repository") f.BoolVar(&o.insecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the repository")
f.BoolVar(&o.allowDeprecatedRepos, "allow-deprecated-repos", false, "by default, this command will not allow adding official repos that have been permanently deleted. This disables that behavior") f.BoolVar(&o.allowDeprecatedRepos, "allow-deprecated-repos", false, "by default, this command will not allow adding official repos that have been permanently deleted. This disables that behavior")
f.BoolVar(&o.passCredentialsAll, "pass-credentials", false, "pass credentials to all domains") f.BoolVar(&o.passCredentialsAll, "pass-credentials", false, "pass credentials to all domains")
f.DurationVar(&o.timeout, "timeout", getter.DefaultHTTPTimeout*time.Second, "time to wait for the index file download to complete")
return cmd return cmd
} }
@ -203,7 +205,7 @@ func (o *repoAddOptions) run(out io.Writer) error {
return nil return nil
} }
r, err := repo.NewChartRepository(&c, getter.All(settings)) r, err := repo.NewChartRepository(&c, getter.All(settings, getter.WithTimeout(o.timeout)))
if err != nil { if err != nil {
return err return err
} }

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"io" "io"
"sync" "sync"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -45,6 +46,7 @@ type repoUpdateOptions struct {
repoFile string repoFile string
repoCache string repoCache string
names []string names []string
timeout time.Duration
failOnRepoUpdateFail bool failOnRepoUpdateFail bool
} }
@ -69,6 +71,7 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command {
} }
f := cmd.Flags() f := cmd.Flags()
f.DurationVar(&o.timeout, "timeout", getter.DefaultHTTPTimeout*time.Second, "time to wait for the index file download to complete")
// Adding this flag for Helm 3 as stop gap functionality for https://github.com/helm/helm/issues/10016. // Adding this flag for Helm 3 as stop gap functionality for https://github.com/helm/helm/issues/10016.
// This should be deprecated in Helm 4 by update to the behaviour of `helm repo update` command. // This should be deprecated in Helm 4 by update to the behaviour of `helm repo update` command.
@ -100,7 +103,7 @@ func (o *repoUpdateOptions) run(out io.Writer) error {
for _, cfg := range f.Repositories { for _, cfg := range f.Repositories {
if updateAllRepos || isRepoRequested(cfg.Name, o.names) { if updateAllRepos || isRepoRequested(cfg.Name, o.names) {
r, err := repo.NewChartRepository(cfg, getter.All(settings)) r, err := repo.NewChartRepository(cfg, getter.All(settings, getter.WithTimeout(o.timeout)))
if err != nil { if err != nil {
return err return err
} }

@ -196,24 +196,32 @@ const (
var defaultOptions = []Option{WithTimeout(time.Second * DefaultHTTPTimeout)} var defaultOptions = []Option{WithTimeout(time.Second * DefaultHTTPTimeout)}
var httpProvider = Provider{ func Getters(extraOpts ...Option) Providers {
Schemes: []string{"http", "https"}, return Providers{
New: func(options ...Option) (Getter, error) { Provider{
options = append(options, defaultOptions...) Schemes: []string{"http", "https"},
return NewHTTPGetter(options...) New: func(options ...Option) (Getter, error) {
}, options = append(options, defaultOptions...)
} options = append(options, extraOpts...)
return NewHTTPGetter(options...)
var ociProvider = Provider{ },
Schemes: []string{registry.OCIScheme}, },
New: NewOCIGetter, Provider{
Schemes: []string{registry.OCIScheme},
New: func(options ...Option) (Getter, error) {
options = append(options, defaultOptions...)
options = append(options, extraOpts...)
return NewOCIGetter(options...)
},
},
}
} }
// All finds all of the registered getters as a list of Provider instances. // All finds all of the registered getters as a list of Provider instances.
// Currently, the built-in getters and the discovered plugins with downloader // Currently, the built-in getters and the discovered plugins with downloader
// notations are collected. // notations are collected.
func All(settings *cli.EnvSettings) Providers { func All(settings *cli.EnvSettings, opts ...Option) Providers {
result := Providers{httpProvider, ociProvider} result := Getters(opts...)
pluginDownloaders, _ := collectPlugins(settings) pluginDownloaders, _ := collectPlugins(settings)
result = append(result, pluginDownloaders...) result = append(result, pluginDownloaders...)
return result return result

@ -17,6 +17,7 @@ package getter
import ( import (
"testing" "testing"
"time"
"helm.sh/helm/v3/pkg/cli" "helm.sh/helm/v3/pkg/cli"
) )
@ -52,6 +53,23 @@ func TestProviders(t *testing.T) {
} }
} }
func TestProvidersWithTimeout(t *testing.T) {
want := time.Hour
getters := Getters(WithTimeout(want))
getter, err := getters.ByScheme("http")
if err != nil {
t.Error(err)
}
client, err := getter.(*HTTPGetter).httpClient()
if err != nil {
t.Error(err)
}
got := client.Timeout
if got != want {
t.Errorf("Expected %q, got %q", want, got)
}
}
func TestAll(t *testing.T) { func TestAll(t *testing.T) {
env := cli.New() env := cli.New()
env.PluginsDirectory = pluginDir env.PluginsDirectory = pluginDir

Loading…
Cancel
Save