Skip to content

Commit 94500d1

Browse files
committed
mitigate issue with chart validation in Helm 3.14 fluxcd#1515
Signed-off-by: ricardo.bartels@telekom.de <ricardo.bartels@telekom.de>
1 parent 54cb2d8 commit 94500d1

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

internal/helm/repository/chart_repository.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"os"
2929
"path"
3030
"sort"
31+
"strings"
3132
"sync"
3233

3334
"github.com/Masterminds/semver/v3"
@@ -91,10 +92,14 @@ func IndexFromBytes(b []byte) (*repo.IndexFile, error) {
9192
if cvs[idx] == nil {
9293
continue
9394
}
95+
// When metadata section missing, initialize with no data
96+
if cvs[idx].Metadata == nil {
97+
cvs[idx].Metadata = &chart.Metadata{}
98+
}
9499
if cvs[idx].APIVersion == "" {
95100
cvs[idx].APIVersion = chart.APIVersionV1
96101
}
97-
if err := cvs[idx].Validate(); err != nil {
102+
if err := cvs[idx].Validate(); ignoreSkippableChartValidationError(err) != nil {
98103
cvs = append(cvs[:idx], cvs[idx+1:]...)
99104
}
100105
}
@@ -501,3 +506,23 @@ func jsonOrYamlUnmarshal(b []byte, i interface{}) error {
501506
}
502507
return yaml.UnmarshalStrict(b, i)
503508
}
509+
510+
// ignoreSkippableChartValidationError inspect the given error and returns nil if
511+
// the error isn't important for index loading
512+
//
513+
// In particular, charts may introduce validations that don't impact repository indexes
514+
// And repository indexes may be generated by older/non-complient software, which doesn't
515+
// conform to all validations.
516+
func ignoreSkippableChartValidationError(err error) error {
517+
verr, ok := err.(chart.ValidationError)
518+
if !ok {
519+
return err
520+
}
521+
522+
// https://github.com/helm/helm/issues/12748 (JFrog repository strips alias field)
523+
if strings.HasPrefix(verr.Error(), "validation: more than one dependency with name or alias") {
524+
return nil
525+
}
526+
527+
return err
528+
}

0 commit comments

Comments
 (0)