From 94500d16a4b382448d2416b22d07d072ce8e8617 Mon Sep 17 00:00:00 2001 From: "ricardo.bartels@telekom.de" Date: Fri, 14 Jun 2024 17:33:15 +0200 Subject: [PATCH] mitigate issue with chart validation in Helm 3.14 #1515 Signed-off-by: ricardo.bartels@telekom.de --- internal/helm/repository/chart_repository.go | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/internal/helm/repository/chart_repository.go b/internal/helm/repository/chart_repository.go index bb279713e..86c5f2338 100644 --- a/internal/helm/repository/chart_repository.go +++ b/internal/helm/repository/chart_repository.go @@ -28,6 +28,7 @@ import ( "os" "path" "sort" + "strings" "sync" "github.com/Masterminds/semver/v3" @@ -91,10 +92,14 @@ func IndexFromBytes(b []byte) (*repo.IndexFile, error) { if cvs[idx] == nil { continue } + // When metadata section missing, initialize with no data + if cvs[idx].Metadata == nil { + cvs[idx].Metadata = &chart.Metadata{} + } if cvs[idx].APIVersion == "" { cvs[idx].APIVersion = chart.APIVersionV1 } - if err := cvs[idx].Validate(); err != nil { + if err := cvs[idx].Validate(); ignoreSkippableChartValidationError(err) != nil { cvs = append(cvs[:idx], cvs[idx+1:]...) } } @@ -501,3 +506,23 @@ func jsonOrYamlUnmarshal(b []byte, i interface{}) error { } return yaml.UnmarshalStrict(b, i) } + +// ignoreSkippableChartValidationError inspect the given error and returns nil if +// the error isn't important for index loading +// +// In particular, charts may introduce validations that don't impact repository indexes +// And repository indexes may be generated by older/non-complient software, which doesn't +// conform to all validations. +func ignoreSkippableChartValidationError(err error) error { + verr, ok := err.(chart.ValidationError) + if !ok { + return err + } + + // https://github.com/helm/helm/issues/12748 (JFrog repository strips alias field) + if strings.HasPrefix(verr.Error(), "validation: more than one dependency with name or alias") { + return nil + } + + return err +}