Skip to content

Commit fb0d7f2

Browse files
committed
internal/helm: validate loaded chart metadata obj
Signed-off-by: Hidde Beydals <hello@hidde.co>
1 parent 750b10e commit fb0d7f2

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

internal/helm/chart/builder_local.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
7979
if err != nil {
8080
return nil, &BuildError{Reason: ErrChartPull, Err: err}
8181
}
82+
if err = curMeta.Validate(); err != nil {
83+
return nil, &BuildError{Reason: ErrChartPull, Err: err}
84+
}
8285

8386
result := &Build{}
8487
result.Name = curMeta.Name
@@ -104,10 +107,14 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
104107
// - BuildOptions.Force is False
105108
if opts.CachedChart != "" && !opts.Force {
106109
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
110+
// If the cached metadata is corrupt, we ignore its existence
111+
// and continue the build
112+
if err = curMeta.Validate(); err == nil {
113+
if result.Name == curMeta.Name && result.Version == curMeta.Version {
114+
result.Path = opts.CachedChart
115+
result.ValuesFiles = opts.ValuesFiles
116+
return result, nil
117+
}
111118
}
112119
}
113120
}

internal/helm/chart/builder_remote.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,14 @@ func (b *remoteChartBuilder) Build(_ context.Context, ref Reference, p string, o
108108
// - BuildOptions.Force is False
109109
if opts.CachedChart != "" && !opts.Force {
110110
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
111+
// If the cached metadata is corrupt, we ignore its existence
112+
// and continue the build
113+
if err = curMeta.Validate(); err == nil {
114+
if result.Name == curMeta.Name && result.Version == curMeta.Version {
115+
result.Path = opts.CachedChart
116+
result.ValuesFiles = opts.GetValuesFiles()
117+
return result, nil
118+
}
115119
}
116120
}
117121
}
@@ -207,9 +211,13 @@ func validatePackageAndWriteToPath(reader io.Reader, out string) error {
207211
if err = tmpFile.Close(); err != nil {
208212
return err
209213
}
210-
if _, err = LoadChartMetadataFromArchive(tmpFile.Name()); err != nil {
214+
meta, err := LoadChartMetadataFromArchive(tmpFile.Name())
215+
if err != nil {
211216
return fmt.Errorf("failed to load chart metadata from written chart: %w", err)
212217
}
218+
if err = meta.Validate(); err != nil {
219+
return fmt.Errorf("failed to validate metadata of written chart: %w", err)
220+
}
213221
if err = fs.RenameWithFallback(tmpFile.Name(), out); err != nil {
214222
return fmt.Errorf("failed to write chart to file: %w", err)
215223
}

0 commit comments

Comments
 (0)