@ -153,6 +153,19 @@ type ChartPathOptions struct {
// registryClient provides a registry client but is not added with
// options from a flag
registryClient * registry . Client
// resolvedRepoURL is the source URL from which the chart was obtained
// during the last LocateChart call. It is independent of RepoURL
// (the --repo input) and is used to record provenance into chart metadata.
resolvedRepoURL string
}
// ResolvedRepoURL returns the source URL from which the chart was obtained
// during the last LocateChart call (a Helm repository URL, an OCI reference,
// or a direct artifact URL). It is empty for local-path installs or when
// LocateChart has not been called.
func ( c * ChartPathOptions ) ResolvedRepoURL ( ) string {
return c . resolvedRepoURL
}
// NewInstall creates a new Install object with the given configuration.
@ -352,12 +365,14 @@ func (i *Install) RunWithContext(ctx context.Context, ch ci.Charter, vals map[st
return nil , fmt . Errorf ( "user supplied labels contains system reserved label name. System labels: %+v" , driver . GetSystemLabels ( ) )
}
// Stamp provenance information into the chart metadata if available from
// the ChartPathOptions. Do not overwrite existing metadata.RepoURL set by
// the chart itself. This ensures library consumers who call actions get
// provenance filled in when LocateChart or a downloader discovered it .
// Stamp provenance information into the chart metadata . Prefer the URL
// discovered by LocateChart (ResolvedRepoURL) and fall back to the --repo
// input for library consumers who set it without calling LocateChart.
// Do not overwrite a value already set in Chart.yaml .
if chrt . Metadata != nil && chrt . Metadata . RepoURL == "" {
if i . ChartPathOptions . RepoURL != "" {
if u := i . ChartPathOptions . ResolvedRepoURL ( ) ; u != "" {
chrt . Metadata . RepoURL = u
} else if i . ChartPathOptions . RepoURL != "" {
chrt . Metadata . RepoURL = i . ChartPathOptions . RepoURL
}
}
@ -896,6 +911,10 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
return "" , fmt . Errorf ( "unable to lookup chart %q, missing registry client" , name )
}
// Reset any provenance recorded by a previous call so callers that reuse
// this instance do not observe stale values from an earlier chart.
c . resolvedRepoURL = ""
name = strings . TrimSpace ( name )
version := strings . TrimSpace ( c . Version )
@ -990,13 +1009,19 @@ func (c *ChartPathOptions) LocateChart(name string, settings *cli.EnvSettings) (
}
// Record provenance information about where the chart was resolved from.
// Prefer the URL discovered by the downloader; fall back to the original
// reference when it is an OCI ref or an absolute URL. Leave RepoURL empty
// for local paths and unresolvable references so callers can distinguish.
if u := dl . RepositoryURL ( ) ; u != "" {
c . RepoURL = u
} else if c . RepoURL == "" && isRemoteChartRef ( name ) {
c . RepoURL = name
// Prefer the URL discovered by the downloader, then the --repo input,
// then the original reference when it is an OCI ref or an absolute URL.
// Local paths and unresolvable references leave resolvedRepoURL empty so
// callers can distinguish them. We deliberately do not mutate RepoURL,
// because it is also the --repo flag input and controls local-path vs
// remote resolution on subsequent calls.
switch {
case dl . RepositoryURL ( ) != "" :
c . resolvedRepoURL = dl . RepositoryURL ( )
case c . RepoURL != "" :
c . resolvedRepoURL = c . RepoURL
case isRemoteChartRef ( name ) :
c . resolvedRepoURL = name
}
lname , err := filepath . Abs ( filename )