Skip to content

Commit

Permalink
internal/helm: ensure cached chart name matches
Browse files Browse the repository at this point in the history
This helps detect e.g. path or chart name reference changes.

Signed-off-by: Hidde Beydals <hello@hidde.co>
  • Loading branch information
hiddeco committed Nov 19, 2021
1 parent 472eb12 commit 88ff049
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
13 changes: 8 additions & 5 deletions internal/helm/chart/builder_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
13 changes: 8 additions & 5 deletions internal/helm/chart/builder_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions internal/helm/chart/builder_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -226,7 +227,7 @@ entries:
}
}

reference := RemoteReference{Name: "grafana"}
reference := RemoteReference{Name: "helmchart"}
repository := mockRepo()

_, err = repository.CacheIndex()
Expand Down

0 comments on commit 88ff049

Please sign in to comment.