Fix panic with OCI for install, upgrade, and show

When range support for OCI went in via #10527 it created a situation
where some lookups for a chart could cause a panic. This change
makes sure the registry client is available to lookup OCI charts

Signed-off-by: Matt Farina <matt.farina@suse.com>
pull/10547/head
Matt Farina 3 years ago
parent 390dacae32
commit 548ec55cf9
No known key found for this signature in database
GPG Key ID: 92C44A3D421FF7F9

@ -165,7 +165,7 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string
newCreateCmd(out), newCreateCmd(out),
newDependencyCmd(actionConfig, out), newDependencyCmd(actionConfig, out),
newPullCmd(actionConfig, out), newPullCmd(actionConfig, out),
newShowCmd(out), newShowCmd(actionConfig, out),
newLintCmd(out), newLintCmd(out),
newPackageCmd(out), newPackageCmd(out),
newRepoCmd(out), newRepoCmd(out),

@ -56,8 +56,8 @@ This command inspects a chart (directory, file, or URL) and displays the content
of the CustomResourceDefinition files of the CustomResourceDefinition files
` `
func newShowCmd(out io.Writer) *cobra.Command { func newShowCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
client := action.NewShow(action.ShowAll) client := action.NewShowWithConfig(action.ShowAll, cfg)
showCommand := &cobra.Command{ showCommand := &cobra.Command{
Use: "show", Use: "show",

@ -117,13 +117,20 @@ type ChartPathOptions struct {
Username string // --username Username string // --username
Verify bool // --verify Verify bool // --verify
Version string // --version Version string // --version
// registryClient provides a registry client but is not added with
// options from a flag
registryClient *registry.Client
} }
// NewInstall creates a new Install object with the given configuration. // NewInstall creates a new Install object with the given configuration.
func NewInstall(cfg *Configuration) *Install { func NewInstall(cfg *Configuration) *Install {
return &Install{ in := &Install{
cfg: cfg, cfg: cfg,
} }
in.ChartPathOptions.registryClient = cfg.RegistryClient
return in
} }
func (i *Install) installCRDs(crds []chart.CRD) error { func (i *Install) installCRDs(crds []chart.CRD) error {
@ -662,6 +669,12 @@ OUTER:
// //
// If 'verify' was set on ChartPathOptions, this will attempt to also verify the chart. // If 'verify' was set on ChartPathOptions, this will attempt to also verify the chart.
func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (string, error) { func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (string, error) {
// If there is no registry client and the name is in an OCI registry return
// an error and a lookup will not occur.
if registry.IsOCI(name) && c.registryClient == nil {
return "", fmt.Errorf("unable to lookup chart %q, missing registry client", name)
}
name = strings.TrimSpace(name) name = strings.TrimSpace(name)
version := strings.TrimSpace(c.Version) version := strings.TrimSpace(c.Version)
@ -692,12 +705,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
}, },
RepositoryConfig: settings.RepositoryConfig, RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache, RepositoryCache: settings.RepositoryCache,
} RegistryClient: c.registryClient,
if registry.IsOCI(name) {
if version != "" {
dl.Options = append(dl.Options, getter.WithTagName(version))
}
} }
if c.Verify { if c.Verify {

@ -64,12 +64,24 @@ type Show struct {
} }
// NewShow creates a new Show object with the given configuration. // NewShow creates a new Show object with the given configuration.
// Deprecated: Use NewShowWithConfig
// TODO Helm 4: Fold NewShowWithConfig back into NewShow
func NewShow(output ShowOutputFormat) *Show { func NewShow(output ShowOutputFormat) *Show {
return &Show{ return &Show{
OutputFormat: output, OutputFormat: output,
} }
} }
// NewShowWithConfig creates a new Show object with the given configuration.
func NewShowWithConfig(output ShowOutputFormat, cfg *Configuration) *Show {
sh := &Show{
OutputFormat: output,
}
sh.ChartPathOptions.registryClient = cfg.RegistryClient
return sh
}
// Run executes 'helm show' against the given release. // Run executes 'helm show' against the given release.
func (s *Show) Run(chartpath string) (string, error) { func (s *Show) Run(chartpath string) (string, error) {
if s.chart == nil { if s.chart == nil {

@ -23,7 +23,8 @@ import (
) )
func TestShow(t *testing.T) { func TestShow(t *testing.T) {
client := NewShow(ShowAll) config := actionConfigFixture(t)
client := NewShowWithConfig(ShowAll, config)
client.chart = &chart.Chart{ client.chart = &chart.Chart{
Metadata: &chart.Metadata{Name: "alpine"}, Metadata: &chart.Metadata{Name: "alpine"},
Files: []*chart.File{ Files: []*chart.File{

@ -112,9 +112,12 @@ type resultMessage struct {
// NewUpgrade creates a new Upgrade object with the given configuration. // NewUpgrade creates a new Upgrade object with the given configuration.
func NewUpgrade(cfg *Configuration) *Upgrade { func NewUpgrade(cfg *Configuration) *Upgrade {
return &Upgrade{ up := &Upgrade{
cfg: cfg, cfg: cfg,
} }
up.ChartPathOptions.registryClient = cfg.RegistryClient
return up
} }
// Run executes the upgrade on the given release. // Run executes the upgrade on the given release.

Loading…
Cancel
Save