internal/helm: ensure cached chart name matches
This helps detect e.g. path or chart name reference changes. Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
parent
472eb12f43
commit
88ff049ab0
|
@ -99,15 +99,18 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all the following is true, we do not need to package the chart:
|
// If all the following is true, we do not need to package the chart:
|
||||||
// - Chart version from current metadata matches calculated version
|
// - Chart name from cached chart matches resolved name
|
||||||
|
// - Chart version from cached chart matches calculated version
|
||||||
// - BuildOptions.Force is False
|
// - BuildOptions.Force is False
|
||||||
if opts.CachedChart != "" && !opts.Force {
|
if opts.CachedChart != "" && !opts.Force {
|
||||||
if curMeta, err = LoadChartMetadataFromArchive(opts.CachedChart); err == nil && result.Version == curMeta.Version {
|
if curMeta, err = LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
|
||||||
|
if result.Name == curMeta.Name && result.Version == curMeta.Version {
|
||||||
result.Path = opts.CachedChart
|
result.Path = opts.CachedChart
|
||||||
result.ValuesFiles = opts.ValuesFiles
|
result.ValuesFiles = opts.ValuesFiles
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If the chart at the path is already packaged and no custom values files
|
// If the chart at the path is already packaged and no custom values files
|
||||||
// options are set, we can copy the chart without making modifications
|
// options are set, we can copy the chart without making modifications
|
||||||
|
|
|
@ -103,15 +103,18 @@ func (b *remoteChartBuilder) Build(_ context.Context, ref Reference, p string, o
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all the following is true, we do not need to download and/or build the chart:
|
// If all the following is true, we do not need to download and/or build the chart:
|
||||||
// - Chart version from current metadata matches calculated version
|
// - Chart name from cached chart matches resolved name
|
||||||
|
// - Chart version from cached chart matches calculated version
|
||||||
// - BuildOptions.Force is False
|
// - BuildOptions.Force is False
|
||||||
if opts.CachedChart != "" && !opts.Force {
|
if opts.CachedChart != "" && !opts.Force {
|
||||||
if curMeta, err := LoadChartMetadataFromArchive(opts.CachedChart); err == nil && result.Version == curMeta.Version {
|
if curMeta, err := LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
|
||||||
|
if result.Name == curMeta.Name && result.Version == curMeta.Version {
|
||||||
result.Path = opts.CachedChart
|
result.Path = opts.CachedChart
|
||||||
result.ValuesFiles = opts.GetValuesFiles()
|
result.ValuesFiles = opts.GetValuesFiles()
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Download the package for the resolved version
|
// Download the package for the resolved version
|
||||||
res, err := b.remote.DownloadChart(cv)
|
res, err := b.remote.DownloadChart(cv)
|
||||||
|
|
|
@ -207,11 +207,12 @@ func TestRemoteBuilder_Build_CachedChart(t *testing.T) {
|
||||||
index := []byte(`
|
index := []byte(`
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
entries:
|
entries:
|
||||||
grafana:
|
helmchart:
|
||||||
- urls:
|
- urls:
|
||||||
- https://example.com/grafana.tgz
|
- https://example.com/helmchart-0.1.0.tgz
|
||||||
description: string
|
description: string
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
name: helmchart
|
||||||
`)
|
`)
|
||||||
|
|
||||||
mockGetter := &mockIndexChartGetter{
|
mockGetter := &mockIndexChartGetter{
|
||||||
|
@ -226,7 +227,7 @@ entries:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reference := RemoteReference{Name: "grafana"}
|
reference := RemoteReference{Name: "helmchart"}
|
||||||
repository := mockRepo()
|
repository := mockRepo()
|
||||||
|
|
||||||
_, err = repository.CacheIndex()
|
_, err = repository.CacheIndex()
|
||||||
|
|
Loading…
Reference in New Issue