From c48942801e3dfc6dc808e70c6d9d1e9dbbe010ce Mon Sep 17 00:00:00 2001 From: iammehrabsandhu Date: Thu, 9 Apr 2026 20:16:34 +0530 Subject: [PATCH] fix: populate chart source provenance for cached OCI charts Addresses review feedback on ResolvedSource not being populated when OCI charts are served from the local cache. Also adds a fallback for direct oci:// references when --repo is not used. - DownloadTo: populate ResolvedSource on cache-hit path - DownloadToCache: populate ResolvedSource on cache-hit path - LocateChart: add OCI ref fallback when RepoURL is empty Signed-off-by: iammehrabsandhu --- pkg/action/install.go | 5 +++++ pkg/downloader/chart_downloader.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pkg/action/install.go b/pkg/action/install.go index 7e38de913..605915324 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -991,6 +991,11 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) ( if c.resolvedSource == nil && c.RepoURL != "" { c.resolvedSource = &rcommon.ChartSource{RepoURL: c.RepoURL} } + // Fallback for direct OCI references (e.g. oci://registry.com/chart:tag) + // where RepoURL is empty and the downloader may not have populated it. + if c.resolvedSource == nil && registry.IsOCI(name) { + c.resolvedSource = &rcommon.ChartSource{RegistryRef: name} + } lname, err := filepath.Abs(filename) if err != nil { diff --git a/pkg/downloader/chart_downloader.go b/pkg/downloader/chart_downloader.go index 0334b7534..99acca228 100644 --- a/pkg/downloader/chart_downloader.go +++ b/pkg/downloader/chart_downloader.go @@ -150,6 +150,15 @@ func (c *ChartDownloader) DownloadTo(ref, version, dest string) (string, *proven } } + // Populate source provenance for cached OCI charts. + // The ref and digest are already known from ResolveChartVersion. + if found && u.Scheme == registry.OCIScheme { + c.ResolvedSource = &rcommon.ChartSource{ + RegistryRef: ref, + Digest: hash, + } + } + if !found { c.Options = append(c.Options, getter.WithAcceptHeader("application/gzip,application/octet-stream")) @@ -266,6 +275,14 @@ func (c *ChartDownloader) DownloadToCache(ref, version string) (string, *provena pth, err = c.Cache.Get(digest32, CacheChart) if err == nil { slog.Debug("found chart in cache", "id", digestString) + + // Populate source provenance for cached OCI charts. + if u.Scheme == registry.OCIScheme { + c.ResolvedSource = &rcommon.ChartSource{ + RegistryRef: ref, + Digest: digestString, + } + } } } if len(digest) == 0 || err != nil {