Skip to content

Commit 88ff049

Browse files
committed
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>
1 parent 472eb12 commit 88ff049

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

internal/helm/chart/builder_local.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,16 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
9999
}
100100

101101
// If all the following is true, we do not need to package the chart:
102-
// - Chart version from current metadata matches calculated version
102+
// - Chart name from cached chart matches resolved name
103+
// - Chart version from cached chart matches calculated version
103104
// - BuildOptions.Force is False
104105
if opts.CachedChart != "" && !opts.Force {
105-
if curMeta, err = LoadChartMetadataFromArchive(opts.CachedChart); err == nil && result.Version == curMeta.Version {
106-
result.Path = opts.CachedChart
107-
result.ValuesFiles = opts.ValuesFiles
108-
return result, nil
106+
if curMeta, err = LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
107+
if result.Name == curMeta.Name && result.Version == curMeta.Version {
108+
result.Path = opts.CachedChart
109+
result.ValuesFiles = opts.ValuesFiles
110+
return result, nil
111+
}
109112
}
110113
}
111114

internal/helm/chart/builder_remote.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,16 @@ func (b *remoteChartBuilder) Build(_ context.Context, ref Reference, p string, o
103103
}
104104

105105
// If all the following is true, we do not need to download and/or build the chart:
106-
// - Chart version from current metadata matches calculated version
106+
// - Chart name from cached chart matches resolved name
107+
// - Chart version from cached chart matches calculated version
107108
// - BuildOptions.Force is False
108109
if opts.CachedChart != "" && !opts.Force {
109-
if curMeta, err := LoadChartMetadataFromArchive(opts.CachedChart); err == nil && result.Version == curMeta.Version {
110-
result.Path = opts.CachedChart
111-
result.ValuesFiles = opts.GetValuesFiles()
112-
return result, nil
110+
if curMeta, err := LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
111+
if result.Name == curMeta.Name && result.Version == curMeta.Version {
112+
result.Path = opts.CachedChart
113+
result.ValuesFiles = opts.GetValuesFiles()
114+
return result, nil
115+
}
113116
}
114117
}
115118

internal/helm/chart/builder_remote_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,12 @@ func TestRemoteBuilder_Build_CachedChart(t *testing.T) {
207207
index := []byte(`
208208
apiVersion: v1
209209
entries:
210-
grafana:
210+
helmchart:
211211
- urls:
212-
- https://example.com/grafana.tgz
212+
- https://example.com/helmchart-0.1.0.tgz
213213
description: string
214214
version: 0.1.0
215+
name: helmchart
215216
`)
216217

217218
mockGetter := &mockIndexChartGetter{
@@ -226,7 +227,7 @@ entries:
226227
}
227228
}
228229

229-
reference := RemoteReference{Name: "grafana"}
230+
reference := RemoteReference{Name: "helmchart"}
230231
repository := mockRepo()
231232

232233
_, err = repository.CacheIndex()

0 commit comments

Comments
 (0)