Skip to content

Commit d6acc00

Browse files
gjenkins8mattfarina
authored andcommitted
Fix: Ignore alias validation error for index load
Signed-off-by: George Jenkins <[email protected]> (cherry picked from commit 68294fd)
1 parent b2738fb commit d6acc00

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

pkg/repo/index.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func loadIndex(data []byte, source string) (*IndexFile, error) {
366366
if cvs[idx].APIVersion == "" {
367367
cvs[idx].APIVersion = chart.APIVersionV1
368368
}
369-
if err := cvs[idx].Validate(); err != nil {
369+
if err := cvs[idx].Validate(); ignoreSkippableChartValidationError(err) != nil {
370370
log.Printf("skipping loading invalid entry for chart %q %q from %s: %s", name, cvs[idx].Version, source, err)
371371
cvs = append(cvs[:idx], cvs[idx+1:]...)
372372
}
@@ -392,3 +392,23 @@ func jsonOrYamlUnmarshal(b []byte, i interface{}) error {
392392
}
393393
return yaml.UnmarshalStrict(b, i)
394394
}
395+
396+
// ignoreSkippableChartValidationError inspect the given error and returns nil if
397+
// the error isn't important for index loading
398+
//
399+
// In particular, charts may introduce validations that don't impact repository indexes
400+
// And repository indexes may be generated by older/non-complient software, which doesn't
401+
// conform to all validations.
402+
func ignoreSkippableChartValidationError(err error) error {
403+
verr, ok := err.(chart.ValidationError)
404+
if !ok {
405+
return err
406+
}
407+
408+
// https://github.com/helm/helm/issues/12748 (JFrog repository strips alias field)
409+
if strings.HasPrefix(verr.Error(), "validation: more than one dependency with name or alias") {
410+
return nil
411+
}
412+
413+
return err
414+
}

pkg/repo/index_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bufio"
2121
"bytes"
2222
"encoding/json"
23+
"fmt"
2324
"net/http"
2425
"os"
2526
"path/filepath"
@@ -596,3 +597,50 @@ func TestAddFileIndexEntriesNil(t *testing.T) {
596597
}
597598
}
598599
}
600+
601+
func TestIgnoreSkippableChartValidationError(t *testing.T) {
602+
type TestCase struct {
603+
Input error
604+
ErrorSkipped bool
605+
}
606+
testCases := map[string]TestCase{
607+
"nil": {
608+
Input: nil,
609+
},
610+
"generic_error": {
611+
Input: fmt.Errorf("foo"),
612+
},
613+
"non_skipped_validation_error": {
614+
Input: chart.ValidationError("chart.metadata.type must be application or library"),
615+
},
616+
"skipped_validation_error": {
617+
Input: chart.ValidationErrorf("more than one dependency with name or alias %q", "foo"),
618+
ErrorSkipped: true,
619+
},
620+
}
621+
622+
for name, tc := range testCases {
623+
t.Run(name, func(t *testing.T) {
624+
result := ignoreSkippableChartValidationError(tc.Input)
625+
626+
if tc.Input == nil {
627+
if result != nil {
628+
t.Error("")
629+
}
630+
return
631+
}
632+
633+
if tc.ErrorSkipped {
634+
if result != nil {
635+
t.Error("")
636+
}
637+
return
638+
}
639+
640+
if tc.Input != result {
641+
t.Error("")
642+
}
643+
644+
})
645+
}
646+
}

0 commit comments

Comments
 (0)