fix(helm): introduce --remote-repo flag

Ignore local directories with the same name as the chart being installed
if --remote-repo is passed.

Fixes #11141

Signed-off-by: Jack Wilsdon <jack+github@wilsdon.me>
pull/12252/head
Jack Wilsdon 2 years ago
parent ca61c326c2
commit 9cc6a9b25c

@ -63,6 +63,7 @@ func addChartPathOptionsFlags(f *pflag.FlagSet, c *action.ChartPathOptions) {
f.BoolVar(&c.InsecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the chart download") f.BoolVar(&c.InsecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the chart download")
f.StringVar(&c.CaFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle") f.StringVar(&c.CaFile, "ca-file", "", "verify certificates of HTTPS-enabled servers using this CA bundle")
f.BoolVar(&c.PassCredentialsAll, "pass-credentials", false, "pass credentials to all domains") f.BoolVar(&c.PassCredentialsAll, "pass-credentials", false, "pass credentials to all domains")
f.BoolVar(&c.RemoteRepo, "remote-repo", false, "force use of chart from remote repository instead of local filesystem")
} }
// bindOutputFlag will add the output flag to the given command and bind the // bindOutputFlag will add the output flag to the given command and bind the

@ -252,6 +252,17 @@ func TestInstall(t *testing.T) {
cmd: fmt.Sprintf("install aeneas test/reqtest --username username --password password --repository-config %s --repository-cache %s", repoFile, srv.Root()), cmd: fmt.Sprintf("install aeneas test/reqtest --username username --password password --repository-config %s --repository-cache %s", repoFile, srv.Root()),
golden: "output/install.txt", golden: "output/install.txt",
}, },
// Verify that a remote chart is used with --remote-repo
{
name: "basic install with --remote-repo",
cmd: "install aeneas reqtest --namespace default --repo " + srv.URL() + " --username username --password password --remote-repo",
golden: "output/install.txt",
},
{
name: "existing local path with --remote-repo",
cmd: "install aeneas testdata/testcharts/empty --namespace default --repo " + srv.URL() + " --username username --password password --remote-repo",
wantError: true,
},
} }
runTestCmd(t, tests) runTestCmd(t, tests)

@ -118,6 +118,7 @@ type ChartPathOptions struct {
Keyring string // --keyring Keyring string // --keyring
Password string // --password Password string // --password
PassCredentialsAll bool // --pass-credentials PassCredentialsAll bool // --pass-credentials
RemoteRepo bool // --remote-repo
RepoURL string // --repo RepoURL string // --repo
Username string // --username Username string // --username
Verify bool // --verify Verify bool // --verify
@ -727,8 +728,8 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
} }
name = strings.TrimSpace(name) name = strings.TrimSpace(name)
version := strings.TrimSpace(c.Version)
if !c.RemoteRepo {
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 {
@ -744,6 +745,13 @@ 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)
} }
}
return c.locateRemoteChart(name, settings)
}
func (c *ChartPathOptions) locateRemoteChart(name string, settings *cli.EnvSettings) (string, error) {
version := strings.TrimSpace(c.Version)
dl := downloader.ChartDownloader{ dl := downloader.ChartDownloader{
Out: os.Stdout, Out: os.Stdout,

Loading…
Cancel
Save