From 88ff049ab02cd268d55c32c373706f9e47fb93db Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Thu, 18 Nov 2021 21:04:56 +0100 Subject: [PATCH] internal/helm: ensure cached chart name matches This helps detect e.g. path or chart name reference changes. Signed-off-by: Hidde Beydals --- internal/helm/chart/builder_local.go | 13 ++++++++----- internal/helm/chart/builder_remote.go | 13 ++++++++----- internal/helm/chart/builder_remote_test.go | 7 ++++--- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/internal/helm/chart/builder_local.go b/internal/helm/chart/builder_local.go index ed9b7bafa..963588815 100644 --- a/internal/helm/chart/builder_local.go +++ b/internal/helm/chart/builder_local.go @@ -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 + } } } diff --git a/internal/helm/chart/builder_remote.go b/internal/helm/chart/builder_remote.go index ab58d0e84..617e2ec5e 100644 --- a/internal/helm/chart/builder_remote.go +++ b/internal/helm/chart/builder_remote.go @@ -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 + } } } diff --git a/internal/helm/chart/builder_remote_test.go b/internal/helm/chart/builder_remote_test.go index a2c33a6fc..56c1fd855 100644 --- a/internal/helm/chart/builder_remote_test.go +++ b/internal/helm/chart/builder_remote_test.go @@ -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()