Skip to content

Commit

Permalink
Merge pull request #503 from fluxcd/helm-validate-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco authored Nov 23, 2021
2 parents 750b10e + fb0d7f2 commit 5419849
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
15 changes: 11 additions & 4 deletions internal/helm/chart/builder_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
}
}
Expand Down
18 changes: 13 additions & 5 deletions internal/helm/chart/builder_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 5419849

Please sign in to comment.