diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index 0fae79534..bba3d9fc9 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -19,9 +19,27 @@ package main import ( "fmt" "testing" + + "helm.sh/helm/v3/pkg/repo/repotest" ) func TestInstall(t *testing.T) { + + srv, err := repotest.NewTempServerWithCleanup(t, "testdata/*.tgz*") + srv.Stop() + if err != nil { + t.Fatal(err) + } + srv.Start() + defer srv.Stop() + if err := srv.CreateIndex(); err != nil { + t.Fatal(err) + } + + if err := srv.LinkIndices(); err != nil { + t.Fatal(err) + } + tests := []cmdTestCase{ // Install, base case { @@ -207,6 +225,12 @@ func TestInstall(t *testing.T) { name: "install chart with only crds", cmd: "install crd-test testdata/testcharts/chart-with-only-crds --namespace default", }, + // Install chart with repoURL + { + name: "install chart with only repoURL", + cmd: "install local-subchart local-subchart --repo " + srv.URL() + " --version 0.1.0", + golden: "output/install-with-repo-url.txt", + }, } runTestActionCmd(t, tests) diff --git a/cmd/helm/testdata/local-subchart-0.1.0.tgz b/cmd/helm/testdata/local-subchart-0.1.0.tgz new file mode 100644 index 000000000..485312105 Binary files /dev/null and b/cmd/helm/testdata/local-subchart-0.1.0.tgz differ diff --git a/cmd/helm/testdata/output/install-with-repo-url.txt b/cmd/helm/testdata/output/install-with-repo-url.txt new file mode 100644 index 000000000..307c6ed77 --- /dev/null +++ b/cmd/helm/testdata/output/install-with-repo-url.txt @@ -0,0 +1,6 @@ +NAME: local-subchart +LAST DEPLOYED: Fri Sep 2 22:04:05 1977 +NAMESPACE: default +STATUS: deployed +REVISION: 1 +TEST SUITE: None diff --git a/pkg/action/install.go b/pkg/action/install.go index c33d6bf3c..78032032e 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -633,20 +633,22 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) ( name = strings.TrimSpace(name) version := strings.TrimSpace(c.Version) - if _, err := os.Stat(name); err == nil { - abs, err := filepath.Abs(name) - if err != nil { - return abs, err - } - if c.Verify { - if _, err := downloader.VerifyChart(abs, c.Keyring); err != nil { - return "", err + if len(c.RepoURL) == 0 { + if _, err := os.Stat(name); err == nil { + abs, err := filepath.Abs(name) + if err != nil { + return abs, err + } + if c.Verify { + if _, err := downloader.VerifyChart(abs, c.Keyring); err != nil { + return "", err + } } + return abs, nil + } + if filepath.IsAbs(name) || strings.HasPrefix(name, ".") { + return name, errors.Errorf("path %q not found", name) } - return abs, nil - } - if filepath.IsAbs(name) || strings.HasPrefix(name, ".") { - return name, errors.Errorf("path %q not found", name) } dl := downloader.ChartDownloader{ @@ -660,6 +662,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) ( }, RepositoryConfig: settings.RepositoryConfig, RepositoryCache: settings.RepositoryCache, + UseRepoURL: len(c.RepoURL) > 0, } if c.Verify { dl.Verify = downloader.VerifyAlways diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 6c600bebb..ae4910c54 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -72,6 +72,7 @@ type ChartDownloader struct { RegistryClient *registry.Client RepositoryConfig string RepositoryCache string + UseRepoURL bool } // DownloadTo retrieves a chart. Depending on the settings, it may also download a provenance file. @@ -158,6 +159,12 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er if err != nil { return nil, errors.Errorf("invalid chart URL format: %s", ref) } + + // It is already resolve, no need to look for the version in the repoconfig + if c.UseRepoURL { + return u, nil + } + c.Options = append(c.Options, getter.WithURL(ref)) rf, err := loadRepoConfig(c.RepositoryConfig) diff --git a/pkg/repo/chartrepo.go b/pkg/repo/chartrepo.go index 09b94fd42..942486734 100644 --- a/pkg/repo/chartrepo.go +++ b/pkg/repo/chartrepo.go @@ -242,6 +242,10 @@ func FindChartInAuthAndTLSRepoURL(repoURL, username, password, chartName, chartV return "", errors.Wrapf(err, "looks like %q is not a valid chart repository or cannot be reached", repoURL) } + // Temporary generation needs to delete + defer os.Remove(filepath.Join(r.CachePath, helmpath.CacheIndexFile(r.Config.Name))) + defer os.Remove(filepath.Join(r.CachePath, helmpath.CacheChartsFile(r.Config.Name))) + // Read the index file for the repository to get chart information and return chart URL repoIndex, err := LoadIndexFile(idx) if err != nil {