From 799c1b6c13f1a0d56cf61ec6a733a58e7274a7e9 Mon Sep 17 00:00:00 2001 From: Luke Reed Date: Wed, 17 Nov 2021 18:08:13 -0500 Subject: [PATCH] populate chart metadata with a repoURL field Signed-off-by: Luke Reed support OCI registries as well Signed-off-by: Luke Reed revert changes to DownloadTo function and implement using the ChartDownloader object instead Signed-off-by: Luke Reed make sure update will still update repoURL Signed-off-by: Luke Reed Signed-off-by: Andy Suderman Set the repository URL to path if a URL is not found Signed-off-by: Andy Suderman Fixes Signed-off-by: Andy Suderman --- cmd/helm/install.go | 6 ++++++ cmd/helm/upgrade.go | 5 +++++ pkg/action/install.go | 1 + pkg/chart/metadata.go | 3 +++ pkg/downloader/chart_downloader.go | 5 +++++ 5 files changed, 20 insertions(+) diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 13c674066..adfa80ef6 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -228,6 +228,12 @@ func runInstall(args []string, client *action.Install, valueOpts *values.Options return nil, err } + if client.ChartPathOptions.RepoURL != "" { + chartRequested.Metadata.RepoURL = client.ChartPathOptions.RepoURL + } else { + chartRequested.Metadata.RepoURL = "path" + } + if err := checkIfInstallable(chartRequested); err != nil { return nil, err } diff --git a/cmd/helm/upgrade.go b/cmd/helm/upgrade.go index 145d342b7..51847d029 100644 --- a/cmd/helm/upgrade.go +++ b/cmd/helm/upgrade.go @@ -158,6 +158,11 @@ func newUpgradeCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { if err != nil { return err } + if client.ChartPathOptions.RepoURL != "" { + ch.Metadata.RepoURL = client.ChartPathOptions.RepoURL + } else { + ch.Metadata.RepoURL = "path" + } if req := ch.Metadata.Dependencies; req != nil { if err := action.CheckDependencies(ch, req); err != nil { err = errors.Wrap(err, "An error occurred while checking for chart dependencies. You may need to run `helm dependency build` to fetch missing dependencies") diff --git a/pkg/action/install.go b/pkg/action/install.go index d5c34cef7..971ce2a39 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -785,6 +785,7 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) ( if err != nil { return "", err } + c.RepoURL = dl.RepositoryURL lname, err := filepath.Abs(filename) if err != nil { diff --git a/pkg/chart/metadata.go b/pkg/chart/metadata.go index ae572abb7..b6749c8a0 100644 --- a/pkg/chart/metadata.go +++ b/pkg/chart/metadata.go @@ -80,6 +80,8 @@ type Metadata struct { Dependencies []*Dependency `json:"dependencies,omitempty"` // Specifies the chart type: application or library Type string `json:"type,omitempty"` + // Specifies the chart URL that was used to initially install a chart. + RepoURL string `json:"repoURL,omitempty"` } // Validate checks the metadata for known issues and sanitizes string @@ -97,6 +99,7 @@ func (md *Metadata) Validate() error { md.Tags = sanitizeString(md.Tags) md.AppVersion = sanitizeString(md.AppVersion) md.KubeVersion = sanitizeString(md.KubeVersion) + md.RepoURL = sanitizeString(md.RepoURL) for i := range md.Sources { md.Sources[i] = sanitizeString(md.Sources[i]) } diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index a95894e00..dbb06df6e 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -73,6 +73,7 @@ type ChartDownloader struct { RegistryClient *registry.Client RepositoryConfig string RepositoryCache string + RepositoryURL string } // DownloadTo retrieves a chart. Depending on the settings, it may also download a provenance file. @@ -196,6 +197,7 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er } if registry.IsOCI(u.String()) { + c.RepositoryURL = ref return c.getOciURI(ref, version, u) } @@ -266,6 +268,9 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (*url.URL, er } if r != nil && r.Config != nil { + if r.Config.URL != "" { + c.RepositoryURL = r.Config.URL + } if r.Config.CertFile != "" || r.Config.KeyFile != "" || r.Config.CAFile != "" { c.Options = append(c.Options, getter.WithTLSClientConfig(r.Config.CertFile, r.Config.KeyFile, r.Config.CAFile)) }