From 5e024b9d854bd558d82adbb25165cb3e365f6712 Mon Sep 17 00:00:00 2001 From: Douglas Camata <159076+douglascamata@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:46:52 +0200 Subject: [PATCH 1/4] Make `ChartRepository`'s cache path customize via the `Entry` Signed-off-by: Douglas Camata <159076+douglascamata@users.noreply.github.com> --- pkg/repo/chartrepo.go | 8 +++++++- pkg/repo/chartrepo_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index 970e96da2..eaf750551 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -48,6 +48,7 @@ type Entry struct { CAFile string `json:"caFile"` InsecureSkipTLSverify bool `json:"insecure_skip_tls_verify"` PassCredentialsAll bool `json:"pass_credentials_all"` + CachePath string `json:"cache_path"` } // ChartRepository represents a chart repository @@ -71,11 +72,16 @@ func NewChartRepository(cfg *Entry, getters getter.Providers) (*ChartRepository, return nil, errors.Errorf("could not find protocol handler for: %s", u.Scheme) } + cachePath := helmpath.CachePath("repository") + if cfg.CachePath != "" { + cachePath = cfg.CachePath + } + return &ChartRepository{ Config: cfg, IndexFile: NewIndexFile(), Client: client, - CachePath: helmpath.CachePath("repository"), + CachePath: cachePath, }, nil } diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index 0a658c0c2..12c18785e 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -73,6 +73,40 @@ func TestLoadChartRepository(t *testing.T) { } } +func TestNewChartRepositoryWithCachePath(t *testing.T) { + srv, err := startLocalServerForTests(nil) + if err != nil { + t.Fatal(err) + } + defer srv.Close() + + cacheDir := t.TempDir() + r, err := NewChartRepository(&Entry{ + Name: testRepository, + URL: srv.URL, + CachePath: cacheDir, + }, getter.All(&cli.EnvSettings{})) + if err != nil { + t.Errorf("Problem creating chart repository from %s: %v", testRepository, err) + } + + if err := r.Load(); err != nil { + t.Errorf("Problem loading chart repository from %s: %v", testRepository, err) + } + + _, err = r.DownloadIndexFile() + if err != nil { + t.Errorf("Problem downloading index file from %s: %v", testRepository, err) + } + + if _, err := os.Stat(filepath.Join(cacheDir, helmpath.CacheIndexFile(r.Config.Name))); err != nil { + t.Errorf("Expected index.yaml to be created in %s, but got an error: %v", cacheDir, err) + } + if _, err := os.Stat(filepath.Join(cacheDir, helmpath.CacheChartsFile(r.Config.Name))); err != nil { + t.Errorf("Expected charts to be created in %s, but got an error: %v", cacheDir, err) + } +} + func TestIndex(t *testing.T) { r, err := NewChartRepository(&Entry{ Name: testRepository, From fecf20e6682e04b659a06f393cb74c8d4d63dc19 Mon Sep 17 00:00:00 2001 From: Douglas Camata <159076+douglascamata@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:48:00 +0200 Subject: [PATCH 2/4] Update `FindChart(.*)` functions with a cache path parameter Signed-off-by: Douglas Camata <159076+douglascamata@users.noreply.github.com> --- pkg/action/install.go | 2 +- pkg/action/pull.go | 2 +- pkg/downloader/manager.go | 2 +- pkg/repo/chartrepo.go | 15 ++++++++------- pkg/repo/chartrepo_test.go | 37 +++++++++++++++++++++++++------------ 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/pkg/action/install.go b/pkg/action/install.go index f81f65749..c835df44c 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -797,7 +797,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) ( } if c.RepoURL != "" { chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(c.RepoURL, c.Username, c.Password, name, version, - c.CertFile, c.KeyFile, c.CaFile, c.InsecureSkipTLSverify, c.PassCredentialsAll, getter.All(settings)) + c.CertFile, c.KeyFile, c.CaFile, c.InsecureSkipTLSverify, c.PassCredentialsAll, getter.All(settings), settings.RepositoryCache) if err != nil { return "", err } diff --git a/pkg/action/pull.go b/pkg/action/pull.go index 787553125..49cabc148 100644 --- a/pkg/action/pull.go +++ b/pkg/action/pull.go @@ -122,7 +122,7 @@ func (p *Pull) Run(chartRef string) (string, error) { } if p.RepoURL != "" { - chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CaFile, p.InsecureSkipTLSverify, p.PassCredentialsAll, getter.All(p.Settings)) + chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CaFile, p.InsecureSkipTLSverify, p.PassCredentialsAll, getter.All(p.Settings), p.Settings.RepositoryCache) if err != nil { return out.String(), err } diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index cc7850aae..9d502cd02 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -742,7 +742,7 @@ func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]* return } } - url, err = repo.FindChartInRepoURL(repoURL, name, version, certFile, keyFile, caFile, m.Getters) + url, err = repo.FindChartInRepoURL(repoURL, name, version, certFile, keyFile, caFile, m.Getters, m.RepositoryCache) if err == nil { return url, username, password, false, false, "", "", "", err } diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index eaf750551..6fb917701 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -204,23 +204,23 @@ func (r *ChartRepository) generateIndex() error { // FindChartInRepoURL finds chart in chart repository pointed by repoURL // without adding repo to repositories -func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers) (string, error) { - return FindChartInAuthRepoURL(repoURL, "", "", chartName, chartVersion, certFile, keyFile, caFile, getters) +func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers, cachePath string) (string, error) { + return FindChartInAuthRepoURL(repoURL, "", "", chartName, chartVersion, certFile, keyFile, caFile, getters, cachePath) } // FindChartInAuthRepoURL finds chart in chart repository pointed by repoURL // without adding repo to repositories, like FindChartInRepoURL, // but it also receives credentials for the chart repository. -func FindChartInAuthRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers) (string, error) { - return FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, false, getters) +func FindChartInAuthRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers, cachePath string) (string, error) { + return FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, false, getters, cachePath) } // FindChartInAuthAndTLSRepoURL finds chart in chart repository pointed by repoURL // without adding repo to repositories, like FindChartInRepoURL, // but it also receives credentials and TLS verify flag for the chart repository. // TODO Helm 4, FindChartInAuthAndTLSRepoURL should be integrated into FindChartInAuthRepoURL. -func FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify bool, getters getter.Providers) (string, error) { - return FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, insecureSkipTLSverify, false, getters) +func FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify bool, getters getter.Providers, cachePath string) (string, error) { + return FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, insecureSkipTLSverify, false, getters, cachePath) } // FindChartInAuthAndTLSAndPassRepoURL finds chart in chart repository pointed by repoURL @@ -228,7 +228,7 @@ func FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartV // but it also receives credentials, TLS verify flag, and if credentials should // be passed on to other domains. // TODO Helm 4, FindChartInAuthAndTLSAndPassRepoURL should be integrated into FindChartInAuthRepoURL. -func FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify, passCredentialsAll bool, getters getter.Providers) (string, error) { +func FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify, passCredentialsAll bool, getters getter.Providers, cachePath string) (string, error) { // Download and write the index file to a temporary location buf := make([]byte, 20) @@ -245,6 +245,7 @@ func FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, CAFile: caFile, Name: name, InsecureSkipTLSverify: insecureSkipTLSverify, + CachePath: cachePath, } r, err := NewChartRepository(&c, getters) if err != nil { diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index 12c18785e..9cc91be03 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -33,6 +33,7 @@ import ( "helm.sh/helm/v3/pkg/chart" "helm.sh/helm/v3/pkg/cli" "helm.sh/helm/v3/pkg/getter" + "helm.sh/helm/v3/pkg/helmpath" ) const ( @@ -331,7 +332,7 @@ func TestFindChartInAuthAndTLSAndPassRepoURL(t *testing.T) { } defer srv.Close() - chartURL, err := FindChartInAuthAndTLSAndPassRepoURL(srv.URL, "", "", "nginx", "", "", "", "", true, false, getter.All(&cli.EnvSettings{})) + chartURL, err := FindChartInAuthAndTLSAndPassRepoURL(srv.URL, "", "", "nginx", "", "", "", "", true, false, getter.All(&cli.EnvSettings{}), "") if err != nil { t.Fatalf("%v", err) } @@ -340,7 +341,7 @@ func TestFindChartInAuthAndTLSAndPassRepoURL(t *testing.T) { } // If the insecureSkipTLSVerify is false, it will return an error that contains "x509: certificate signed by unknown authority". - _, err = FindChartInAuthAndTLSAndPassRepoURL(srv.URL, "", "", "nginx", "0.1.0", "", "", "", false, false, getter.All(&cli.EnvSettings{})) + _, err = FindChartInAuthAndTLSAndPassRepoURL(srv.URL, "", "", "nginx", "0.1.0", "", "", "", false, false, getter.All(&cli.EnvSettings{}), "") // Go communicates with the platform and different platforms return different messages. Go itself tests darwin // differently for its message. On newer versions of Darwin the message includes the "Acme Co" portion while older // versions of Darwin do not. As there are people developing Helm using both old and new versions of Darwin we test @@ -361,7 +362,7 @@ func TestFindChartInRepoURL(t *testing.T) { } defer srv.Close() - chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(&cli.EnvSettings{})) + chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(&cli.EnvSettings{}), "") if err != nil { t.Fatalf("%v", err) } @@ -369,7 +370,7 @@ func TestFindChartInRepoURL(t *testing.T) { t.Errorf("%s is not the valid URL", chartURL) } - chartURL, err = FindChartInRepoURL(srv.URL, "nginx", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{})) + chartURL, err = FindChartInRepoURL(srv.URL, "nginx", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{}), "") if err != nil { t.Errorf("%s", err) } @@ -378,13 +379,25 @@ func TestFindChartInRepoURL(t *testing.T) { } } -func TestErrorFindChartInRepoURL(t *testing.T) { +func TestFindChartInRepoURLWithCachePath(t *testing.T) { + srv, err := startLocalServerForTests(nil) + if err != nil { + t.Fatal(err) + } + defer srv.Close() - g := getter.All(&cli.EnvSettings{ - RepositoryCache: t.TempDir(), - }) + cacheDir := t.TempDir() + chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(&cli.EnvSettings{}), cacheDir) + if err != nil { + t.Fatalf("%v", err) + } + if chartURL != "https://charts.helm.sh/stable/nginx-0.2.0.tgz" { + t.Errorf("%s is not the valid URL", chartURL) + } +} - if _, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", g); err == nil { +func TestErrorFindChartInRepoURL(t *testing.T) { + if _, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", getter.All(&cli.EnvSettings{}), ""); err == nil { t.Errorf("Expected error for bad chart URL, but did not get any errors") } else if !strings.Contains(err.Error(), `looks like "http://someserver/something" is not a valid chart repository or cannot be reached`) { t.Errorf("Expected error for bad chart URL, but got a different error (%v)", err) @@ -396,19 +409,19 @@ func TestErrorFindChartInRepoURL(t *testing.T) { } defer srv.Close() - if _, err = FindChartInRepoURL(srv.URL, "nginx1", "", "", "", "", g); err == nil { + if _, err = FindChartInRepoURL(srv.URL, "nginx1", "", "", "", "", getter.All(&cli.EnvSettings{}), ""); err == nil { t.Errorf("Expected error for chart not found, but did not get any errors") } else if err.Error() != `chart "nginx1" not found in `+srv.URL+` repository` { t.Errorf("Expected error for chart not found, but got a different error (%v)", err) } - if _, err = FindChartInRepoURL(srv.URL, "nginx1", "0.1.0", "", "", "", g); err == nil { + if _, err = FindChartInRepoURL(srv.URL, "nginx1", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{}), ""); err == nil { t.Errorf("Expected error for chart not found, but did not get any errors") } else if err.Error() != `chart "nginx1" version "0.1.0" not found in `+srv.URL+` repository` { t.Errorf("Expected error for chart not found, but got a different error (%v)", err) } - if _, err = FindChartInRepoURL(srv.URL, "chartWithNoURL", "", "", "", "", g); err == nil { + if _, err = FindChartInRepoURL(srv.URL, "chartWithNoURL", "", "", "", "", getter.All(&cli.EnvSettings{}), ""); err == nil { t.Errorf("Expected error for no chart URLs available, but did not get any errors") } else if err.Error() != `chart "chartWithNoURL" has no downloadable URLs` { t.Errorf("Expected error for chart not found, but got a different error (%v)", err) From 7fca7d505f29e419d758710443cfca1fc1417d7b Mon Sep 17 00:00:00 2001 From: Douglas Camata <159076+douglascamata@users.noreply.github.com> Date: Fri, 25 Jul 2025 15:54:56 +0200 Subject: [PATCH 3/4] Remove `CachePath` from `Entry` It will have to be customized manually in `ChartRepository` after its creation. Signed-off-by: Douglas Camata <159076+douglascamata@users.noreply.github.com> --- pkg/repo/chartrepo.go | 12 ++++-------- pkg/repo/chartrepo_test.go | 7 ++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index 6fb917701..251bf534d 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -48,7 +48,6 @@ type Entry struct { CAFile string `json:"caFile"` InsecureSkipTLSverify bool `json:"insecure_skip_tls_verify"` PassCredentialsAll bool `json:"pass_credentials_all"` - CachePath string `json:"cache_path"` } // ChartRepository represents a chart repository @@ -72,16 +71,11 @@ func NewChartRepository(cfg *Entry, getters getter.Providers) (*ChartRepository, return nil, errors.Errorf("could not find protocol handler for: %s", u.Scheme) } - cachePath := helmpath.CachePath("repository") - if cfg.CachePath != "" { - cachePath = cfg.CachePath - } - return &ChartRepository{ Config: cfg, IndexFile: NewIndexFile(), Client: client, - CachePath: cachePath, + CachePath: helmpath.CachePath("repository"), }, nil } @@ -245,12 +239,14 @@ func FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, CAFile: caFile, Name: name, InsecureSkipTLSverify: insecureSkipTLSverify, - CachePath: cachePath, } r, err := NewChartRepository(&c, getters) if err != nil { return "", err } + if cachePath != "" { + r.CachePath = cachePath + } idx, err := r.DownloadIndexFile() if err != nil { return "", errors.Wrapf(err, "looks like %q is not a valid chart repository or cannot be reached", repoURL) diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index 9cc91be03..49d57cce0 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -83,14 +83,15 @@ func TestNewChartRepositoryWithCachePath(t *testing.T) { cacheDir := t.TempDir() r, err := NewChartRepository(&Entry{ - Name: testRepository, - URL: srv.URL, - CachePath: cacheDir, + Name: testRepository, + URL: srv.URL, }, getter.All(&cli.EnvSettings{})) if err != nil { t.Errorf("Problem creating chart repository from %s: %v", testRepository, err) } + r.CachePath = cacheDir + if err := r.Load(); err != nil { t.Errorf("Problem loading chart repository from %s: %v", testRepository, err) } From b05e1c6d965f47a9b98c888ea15673f6ee485717 Mon Sep 17 00:00:00 2001 From: Douglas Camata <159076+douglascamata@users.noreply.github.com> Date: Fri, 25 Jul 2025 23:03:42 +0200 Subject: [PATCH 4/4] Preserve backwards compatibility of exported functions Signed-off-by: Douglas Camata <159076+douglascamata@users.noreply.github.com> --- pkg/action/install.go | 2 +- pkg/action/pull.go | 2 +- pkg/downloader/manager.go | 2 +- pkg/repo/chartrepo.go | 21 ++++++++++++++------- pkg/repo/chartrepo_test.go | 20 ++++++++++---------- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/pkg/action/install.go b/pkg/action/install.go index c835df44c..c68e037b2 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -796,7 +796,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) ( dl.Verify = downloader.VerifyAlways } if c.RepoURL != "" { - chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(c.RepoURL, c.Username, c.Password, name, version, + chartURL, err := repo.FindChartInAuthAndTLSAndPassAndCacheRepoURL(c.RepoURL, c.Username, c.Password, name, version, c.CertFile, c.KeyFile, c.CaFile, c.InsecureSkipTLSverify, c.PassCredentialsAll, getter.All(settings), settings.RepositoryCache) if err != nil { return "", err diff --git a/pkg/action/pull.go b/pkg/action/pull.go index 49cabc148..4389166da 100644 --- a/pkg/action/pull.go +++ b/pkg/action/pull.go @@ -122,7 +122,7 @@ func (p *Pull) Run(chartRef string) (string, error) { } if p.RepoURL != "" { - chartURL, err := repo.FindChartInAuthAndTLSAndPassRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CaFile, p.InsecureSkipTLSverify, p.PassCredentialsAll, getter.All(p.Settings), p.Settings.RepositoryCache) + chartURL, err := repo.FindChartInAuthAndTLSAndPassAndCacheRepoURL(p.RepoURL, p.Username, p.Password, chartRef, p.Version, p.CertFile, p.KeyFile, p.CaFile, p.InsecureSkipTLSverify, p.PassCredentialsAll, getter.All(p.Settings), p.Settings.RepositoryCache) if err != nil { return out.String(), err } diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 9d502cd02..08d3e545e 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -742,7 +742,7 @@ func (m *Manager) findChartURL(name, version, repoURL string, repos map[string]* return } } - url, err = repo.FindChartInRepoURL(repoURL, name, version, certFile, keyFile, caFile, m.Getters, m.RepositoryCache) + url, err = repo.FindChartInAuthAndTLSAndPassAndCacheRepoURL(repoURL, "", "", name, version, certFile, keyFile, caFile, false, false, m.Getters, m.RepositoryCache) if err == nil { return url, username, password, false, false, "", "", "", err } diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index 251bf534d..49b7d9b9f 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -198,23 +198,23 @@ func (r *ChartRepository) generateIndex() error { // FindChartInRepoURL finds chart in chart repository pointed by repoURL // without adding repo to repositories -func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers, cachePath string) (string, error) { - return FindChartInAuthRepoURL(repoURL, "", "", chartName, chartVersion, certFile, keyFile, caFile, getters, cachePath) +func FindChartInRepoURL(repoURL, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers) (string, error) { + return FindChartInAuthRepoURL(repoURL, "", "", chartName, chartVersion, certFile, keyFile, caFile, getters) } // FindChartInAuthRepoURL finds chart in chart repository pointed by repoURL // without adding repo to repositories, like FindChartInRepoURL, // but it also receives credentials for the chart repository. -func FindChartInAuthRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers, cachePath string) (string, error) { - return FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, false, getters, cachePath) +func FindChartInAuthRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, getters getter.Providers) (string, error) { + return FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, false, getters) } // FindChartInAuthAndTLSRepoURL finds chart in chart repository pointed by repoURL // without adding repo to repositories, like FindChartInRepoURL, // but it also receives credentials and TLS verify flag for the chart repository. // TODO Helm 4, FindChartInAuthAndTLSRepoURL should be integrated into FindChartInAuthRepoURL. -func FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify bool, getters getter.Providers, cachePath string) (string, error) { - return FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, insecureSkipTLSverify, false, getters, cachePath) +func FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify bool, getters getter.Providers) (string, error) { + return FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, insecureSkipTLSverify, false, getters) } // FindChartInAuthAndTLSAndPassRepoURL finds chart in chart repository pointed by repoURL @@ -222,8 +222,15 @@ func FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartV // but it also receives credentials, TLS verify flag, and if credentials should // be passed on to other domains. // TODO Helm 4, FindChartInAuthAndTLSAndPassRepoURL should be integrated into FindChartInAuthRepoURL. -func FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify, passCredentialsAll bool, getters getter.Providers, cachePath string) (string, error) { +func FindChartInAuthAndTLSAndPassRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify, passCredentialsAll bool, getters getter.Providers) (string, error) { + return FindChartInAuthAndTLSAndPassAndCacheRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile, insecureSkipTLSverify, passCredentialsAll, getters, "") +} +// FindChartInAuthAndTLSAndPassAndCacheRepoURL finds chart in chart repository pointed by repoURL +// without adding repo to repositories, like FindChartInRepoURL, +// but it also receives credentials, TLS verify flag, if credentials should +// be passed on to other domains, and a custom cache path. +func FindChartInAuthAndTLSAndPassAndCacheRepoURL(repoURL, username, password, chartName, chartVersion, certFile, keyFile, caFile string, insecureSkipTLSverify, passCredentialsAll bool, getters getter.Providers, cachePath string) (string, error) { // Download and write the index file to a temporary location buf := make([]byte, 20) rand.Read(buf) diff --git a/pkg/repo/chartrepo_test.go b/pkg/repo/chartrepo_test.go index 49d57cce0..12afbfe08 100644 --- a/pkg/repo/chartrepo_test.go +++ b/pkg/repo/chartrepo_test.go @@ -333,7 +333,7 @@ func TestFindChartInAuthAndTLSAndPassRepoURL(t *testing.T) { } defer srv.Close() - chartURL, err := FindChartInAuthAndTLSAndPassRepoURL(srv.URL, "", "", "nginx", "", "", "", "", true, false, getter.All(&cli.EnvSettings{}), "") + chartURL, err := FindChartInAuthAndTLSAndPassRepoURL(srv.URL, "", "", "nginx", "", "", "", "", true, false, getter.All(&cli.EnvSettings{})) if err != nil { t.Fatalf("%v", err) } @@ -342,7 +342,7 @@ func TestFindChartInAuthAndTLSAndPassRepoURL(t *testing.T) { } // If the insecureSkipTLSVerify is false, it will return an error that contains "x509: certificate signed by unknown authority". - _, err = FindChartInAuthAndTLSAndPassRepoURL(srv.URL, "", "", "nginx", "0.1.0", "", "", "", false, false, getter.All(&cli.EnvSettings{}), "") + _, err = FindChartInAuthAndTLSAndPassRepoURL(srv.URL, "", "", "nginx", "0.1.0", "", "", "", false, false, getter.All(&cli.EnvSettings{})) // Go communicates with the platform and different platforms return different messages. Go itself tests darwin // differently for its message. On newer versions of Darwin the message includes the "Acme Co" portion while older // versions of Darwin do not. As there are people developing Helm using both old and new versions of Darwin we test @@ -363,7 +363,7 @@ func TestFindChartInRepoURL(t *testing.T) { } defer srv.Close() - chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(&cli.EnvSettings{}), "") + chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(&cli.EnvSettings{})) if err != nil { t.Fatalf("%v", err) } @@ -371,7 +371,7 @@ func TestFindChartInRepoURL(t *testing.T) { t.Errorf("%s is not the valid URL", chartURL) } - chartURL, err = FindChartInRepoURL(srv.URL, "nginx", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{}), "") + chartURL, err = FindChartInRepoURL(srv.URL, "nginx", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{})) if err != nil { t.Errorf("%s", err) } @@ -380,7 +380,7 @@ func TestFindChartInRepoURL(t *testing.T) { } } -func TestFindChartInRepoURLWithCachePath(t *testing.T) { +func TestFindChartInAuthAndTLSAndPassAndCacheRepoURL(t *testing.T) { srv, err := startLocalServerForTests(nil) if err != nil { t.Fatal(err) @@ -388,7 +388,7 @@ func TestFindChartInRepoURLWithCachePath(t *testing.T) { defer srv.Close() cacheDir := t.TempDir() - chartURL, err := FindChartInRepoURL(srv.URL, "nginx", "", "", "", "", getter.All(&cli.EnvSettings{}), cacheDir) + chartURL, err := FindChartInAuthAndTLSAndPassAndCacheRepoURL(srv.URL, "", "", "nginx", "", "", "", "", false, false, getter.All(&cli.EnvSettings{}), cacheDir) if err != nil { t.Fatalf("%v", err) } @@ -398,7 +398,7 @@ func TestFindChartInRepoURLWithCachePath(t *testing.T) { } func TestErrorFindChartInRepoURL(t *testing.T) { - if _, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", getter.All(&cli.EnvSettings{}), ""); err == nil { + if _, err := FindChartInRepoURL("http://someserver/something", "nginx", "", "", "", "", getter.All(&cli.EnvSettings{})); err == nil { t.Errorf("Expected error for bad chart URL, but did not get any errors") } else if !strings.Contains(err.Error(), `looks like "http://someserver/something" is not a valid chart repository or cannot be reached`) { t.Errorf("Expected error for bad chart URL, but got a different error (%v)", err) @@ -410,19 +410,19 @@ func TestErrorFindChartInRepoURL(t *testing.T) { } defer srv.Close() - if _, err = FindChartInRepoURL(srv.URL, "nginx1", "", "", "", "", getter.All(&cli.EnvSettings{}), ""); err == nil { + if _, err = FindChartInRepoURL(srv.URL, "nginx1", "", "", "", "", getter.All(&cli.EnvSettings{})); err == nil { t.Errorf("Expected error for chart not found, but did not get any errors") } else if err.Error() != `chart "nginx1" not found in `+srv.URL+` repository` { t.Errorf("Expected error for chart not found, but got a different error (%v)", err) } - if _, err = FindChartInRepoURL(srv.URL, "nginx1", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{}), ""); err == nil { + if _, err = FindChartInRepoURL(srv.URL, "nginx1", "0.1.0", "", "", "", getter.All(&cli.EnvSettings{})); err == nil { t.Errorf("Expected error for chart not found, but did not get any errors") } else if err.Error() != `chart "nginx1" version "0.1.0" not found in `+srv.URL+` repository` { t.Errorf("Expected error for chart not found, but got a different error (%v)", err) } - if _, err = FindChartInRepoURL(srv.URL, "chartWithNoURL", "", "", "", "", getter.All(&cli.EnvSettings{}), ""); err == nil { + if _, err = FindChartInRepoURL(srv.URL, "chartWithNoURL", "", "", "", "", getter.All(&cli.EnvSettings{})); err == nil { t.Errorf("Expected error for no chart URLs available, but did not get any errors") } else if err.Error() != `chart "chartWithNoURL" has no downloadable URLs` { t.Errorf("Expected error for chart not found, but got a different error (%v)", err)