internal/helm: validate loaded chart metadata obj
Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
parent
750b10e57b
commit
fb0d7f24c8
|
@ -79,6 +79,9 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &BuildError{Reason: ErrChartPull, Err: err}
|
return nil, &BuildError{Reason: ErrChartPull, Err: err}
|
||||||
}
|
}
|
||||||
|
if err = curMeta.Validate(); err != nil {
|
||||||
|
return nil, &BuildError{Reason: ErrChartPull, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
result := &Build{}
|
result := &Build{}
|
||||||
result.Name = curMeta.Name
|
result.Name = curMeta.Name
|
||||||
|
@ -104,10 +107,14 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
|
||||||
// - BuildOptions.Force is False
|
// - BuildOptions.Force is False
|
||||||
if opts.CachedChart != "" && !opts.Force {
|
if opts.CachedChart != "" && !opts.Force {
|
||||||
if curMeta, err = LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
|
if curMeta, err = LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
|
||||||
if result.Name == curMeta.Name && result.Version == curMeta.Version {
|
// If the cached metadata is corrupt, we ignore its existence
|
||||||
result.Path = opts.CachedChart
|
// and continue the build
|
||||||
result.ValuesFiles = opts.ValuesFiles
|
if err = curMeta.Validate(); err == nil {
|
||||||
return result, nil
|
if result.Name == curMeta.Name && result.Version == curMeta.Version {
|
||||||
|
result.Path = opts.CachedChart
|
||||||
|
result.ValuesFiles = opts.ValuesFiles
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,10 +108,14 @@ func (b *remoteChartBuilder) Build(_ context.Context, ref Reference, p string, o
|
||||||
// - BuildOptions.Force is False
|
// - BuildOptions.Force is False
|
||||||
if opts.CachedChart != "" && !opts.Force {
|
if opts.CachedChart != "" && !opts.Force {
|
||||||
if curMeta, err := LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
|
if curMeta, err := LoadChartMetadataFromArchive(opts.CachedChart); err == nil {
|
||||||
if result.Name == curMeta.Name && result.Version == curMeta.Version {
|
// If the cached metadata is corrupt, we ignore its existence
|
||||||
result.Path = opts.CachedChart
|
// and continue the build
|
||||||
result.ValuesFiles = opts.GetValuesFiles()
|
if err = curMeta.Validate(); err == nil {
|
||||||
return result, 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 {
|
if err = tmpFile.Close(); err != nil {
|
||||||
return err
|
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)
|
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 {
|
if err = fs.RenameWithFallback(tmpFile.Name(), out); err != nil {
|
||||||
return fmt.Errorf("failed to write chart to file: %w", err)
|
return fmt.Errorf("failed to write chart to file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue