From 1f52a0e0e6f4da74e295271269c3965acbeab3c8 Mon Sep 17 00:00:00 2001 From: Luke Reed Date: Wed, 17 Nov 2021 18:08:13 -0500 Subject: [PATCH 1/2] 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 Signed-off-by: Aleksei Krugliak --- internal/chart/v3/metadata.go | 3 +++ pkg/action/install.go | 1 + pkg/cmd/install.go | 6 ++++++ pkg/cmd/upgrade.go | 5 +++++ pkg/downloader/chart_downloader.go | 13 ++++++------- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/internal/chart/v3/metadata.go b/internal/chart/v3/metadata.go index 4629d571b..30f433a29 100644 --- a/internal/chart/v3/metadata.go +++ b/internal/chart/v3/metadata.go @@ -81,6 +81,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 @@ -98,6 +100,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/action/install.go b/pkg/action/install.go index 0fe1f1a6e..776501a64 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -964,6 +964,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/cmd/install.go b/pkg/cmd/install.go index d36cd9e34..6f1576b48 100644 --- a/pkg/cmd/install.go +++ b/pkg/cmd/install.go @@ -262,6 +262,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" + } + ac, err := chart.NewAccessor(chartRequested) if err != nil { return nil, err diff --git a/pkg/cmd/upgrade.go b/pkg/cmd/upgrade.go index 918d6f5b8..821cb49c1 100644 --- a/pkg/cmd/upgrade.go +++ b/pkg/cmd/upgrade.go @@ -197,6 +197,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" + } ac, err := ci.NewAccessor(ch) if err != nil { diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index ee4f8abe3..c234f348c 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -84,7 +84,8 @@ type ChartDownloader struct { ContentCache string // Cache specifies the cache implementation to use. - Cache Cache + Cache Cache + RepositoryURL string } // DownloadTo retrieves a chart. Depending on the settings, it may also download a provenance file. @@ -356,12 +357,7 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (string, *url } if registry.IsOCI(u.String()) { - if c.RegistryClient == nil { - return "", nil, fmt.Errorf("unable to lookup ref %s at version '%s', missing registry client", ref, version) - } - - digest, OCIref, err := c.RegistryClient.ValidateReference(ref, version, u) - return digest, OCIref, err + return c.getOciURI(ref, version, u) } rf, err := loadRepoConfig(c.RepositoryConfig) @@ -430,6 +426,9 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (string, *url } 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)) } From 31132a16fe722535fd593371f66c0e012934de33 Mon Sep 17 00:00:00 2001 From: Aleksei Krugliak Date: Thu, 5 Feb 2026 19:39:22 +0200 Subject: [PATCH 2/2] Fix accidentaly deleted code Signed-off-by: Aleksei Krugliak --- pkg/downloader/chart_downloader.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index c234f348c..73ade62c3 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -357,7 +357,12 @@ func (c *ChartDownloader) ResolveChartVersion(ref, version string) (string, *url } if registry.IsOCI(u.String()) { - return c.getOciURI(ref, version, u) + if c.RegistryClient == nil { + return "", nil, fmt.Errorf("unable to lookup ref %s at version '%s', missing registry client", ref, version) + } + + digest, OCIref, err := c.RegistryClient.ValidateReference(ref, version, u) + return digest, OCIref, err } rf, err := loadRepoConfig(c.RepositoryConfig)