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:
Hidde Beydals 2021-11-18 21:04:56 +01:00
parent 472eb12f43
commit 88ff049ab0
3 changed files with 20 additions and 13 deletions

View File

@ -99,13 +99,16 @@ 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:
// - 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
if opts.CachedChart != "" && !opts.Force {
if curMeta, err = LoadChartMetadataFromArchive(opts.CachedChart); err == nil && result.Version == curMeta.Version {
result.Path = opts.CachedChart
result.ValuesFiles = opts.ValuesFiles
return result, nil
if curMeta, err = LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
if result.Name == curMeta.Name && result.Version == curMeta.Version {
result.Path = opts.CachedChart
result.ValuesFiles = opts.ValuesFiles
return result, nil
}
}
}

View File

@ -103,13 +103,16 @@ 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:
// - 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
if opts.CachedChart != "" && !opts.Force {
if curMeta, err := LoadChartMetadataFromArchive(opts.CachedChart); err == nil && result.Version == curMeta.Version {
result.Path = opts.CachedChart
result.ValuesFiles = opts.GetValuesFiles()
return result, nil
if curMeta, err := LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
if result.Name == curMeta.Name && result.Version == curMeta.Version {
result.Path = opts.CachedChart
result.ValuesFiles = opts.GetValuesFiles()
return result, nil
}
}
}

View File

@ -207,11 +207,12 @@ func TestRemoteBuilder_Build_CachedChart(t *testing.T) {
index := []byte(`
apiVersion: v1
entries:
grafana:
helmchart:
- urls:
- https://example.com/grafana.tgz
- https://example.com/helmchart-0.1.0.tgz
description: string
version: 0.1.0
name: helmchart
`)
mockGetter := &mockIndexChartGetter{
@ -226,7 +227,7 @@ entries:
}
}
reference := RemoteReference{Name: "grafana"}
reference := RemoteReference{Name: "helmchart"}
repository := mockRepo()
_, err = repository.CacheIndex()