diff --git a/internal/helm/chart/builder_local.go b/internal/helm/chart/builder_local.go index 963588815..721238fe9 100644 --- a/internal/helm/chart/builder_local.go +++ b/internal/helm/chart/builder_local.go @@ -79,6 +79,9 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string, if err != nil { return nil, &BuildError{Reason: ErrChartPull, Err: err} } + if err = curMeta.Validate(); err != nil { + return nil, &BuildError{Reason: ErrChartPull, Err: err} + } result := &Build{} result.Name = curMeta.Name @@ -104,10 +107,14 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string, // - BuildOptions.Force is False if opts.CachedChart != "" && !opts.Force { 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 + // If the cached metadata is corrupt, we ignore its existence + // and continue the build + if err = curMeta.Validate(); 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 617e2ec5e..3252ff226 100644 --- a/internal/helm/chart/builder_remote.go +++ b/internal/helm/chart/builder_remote.go @@ -108,10 +108,14 @@ func (b *remoteChartBuilder) Build(_ context.Context, ref Reference, p string, o // - BuildOptions.Force is False if opts.CachedChart != "" && !opts.Force { 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 + // If the cached metadata is corrupt, we ignore its existence + // and continue the build + if err = curMeta.Validate(); err == nil { + if result.Name == curMeta.Name && result.Version == curMeta.Version { + result.Path = opts.CachedChart + result.ValuesFiles = opts.GetValuesFiles() + return result, nil + } } } } @@ -207,9 +211,13 @@ func validatePackageAndWriteToPath(reader io.Reader, out string) error { if err = tmpFile.Close(); err != nil { return err } - if _, err = LoadChartMetadataFromArchive(tmpFile.Name()); err != nil { + meta, err := LoadChartMetadataFromArchive(tmpFile.Name()) + if err != nil { return fmt.Errorf("failed to load chart metadata from written chart: %w", err) } + if err = meta.Validate(); err != nil { + return fmt.Errorf("failed to validate metadata of written chart: %w", err) + } if err = fs.RenameWithFallback(tmpFile.Name(), out); err != nil { return fmt.Errorf("failed to write chart to file: %w", err) }