fix(repo option): fix a problem with helm template/install when specifying --repo

Signed-off-by: cndoit18 <cndoit18@outlook.com>
pull/9746/head
cndoit18 4 years ago
parent bf486a25cd
commit dc52f8f33a
No known key found for this signature in database
GPG Key ID: A5E54CE7AC730381

@ -19,9 +19,27 @@ package main
import ( import (
"fmt" "fmt"
"testing" "testing"
"helm.sh/helm/v3/pkg/repo/repotest"
) )
func TestInstall(t *testing.T) { 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{ tests := []cmdTestCase{
// Install, base case // Install, base case
{ {
@ -207,6 +225,12 @@ func TestInstall(t *testing.T) {
name: "install chart with only crds", name: "install chart with only crds",
cmd: "install crd-test testdata/testcharts/chart-with-only-crds --namespace default", 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) runTestActionCmd(t, tests)

Binary file not shown.

@ -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

@ -633,6 +633,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
name = strings.TrimSpace(name) name = strings.TrimSpace(name)
version := strings.TrimSpace(c.Version) version := strings.TrimSpace(c.Version)
if len(c.RepoURL) == 0 {
if _, err := os.Stat(name); err == nil { if _, err := os.Stat(name); err == nil {
abs, err := filepath.Abs(name) abs, err := filepath.Abs(name)
if err != nil { if err != nil {
@ -648,6 +649,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
if filepath.IsAbs(name) || strings.HasPrefix(name, ".") { if filepath.IsAbs(name) || strings.HasPrefix(name, ".") {
return name, errors.Errorf("path %q not found", name) return name, errors.Errorf("path %q not found", name)
} }
}
dl := downloader.ChartDownloader{ dl := downloader.ChartDownloader{
Out: os.Stdout, Out: os.Stdout,
@ -660,6 +662,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
}, },
RepositoryConfig: settings.RepositoryConfig, RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache, RepositoryCache: settings.RepositoryCache,
UseRepoURL: len(c.RepoURL) > 0,
} }
if c.Verify { if c.Verify {
dl.Verify = downloader.VerifyAlways dl.Verify = downloader.VerifyAlways

@ -72,6 +72,7 @@ type ChartDownloader struct {
RegistryClient *registry.Client RegistryClient *registry.Client
RepositoryConfig string RepositoryConfig string
RepositoryCache string RepositoryCache string
UseRepoURL bool
} }
// DownloadTo retrieves a chart. Depending on the settings, it may also download a provenance file. // 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 { if err != nil {
return nil, errors.Errorf("invalid chart URL format: %s", ref) 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)) c.Options = append(c.Options, getter.WithURL(ref))
rf, err := loadRepoConfig(c.RepositoryConfig) rf, err := loadRepoConfig(c.RepositoryConfig)

@ -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) 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 // Read the index file for the repository to get chart information and return chart URL
repoIndex, err := LoadIndexFile(idx) repoIndex, err := LoadIndexFile(idx)
if err != nil { if err != nil {

Loading…
Cancel
Save