From dd8502f7b4fd5824a696c99909babd0fbed77e9e Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Tue, 29 Jul 2025 15:37:57 -0400 Subject: [PATCH 1/2] Handle messy index files Signed-off-by: Matt Farina (cherry picked from commit 69efc0d4fbcc143e0b196253f6e82808aaa57fc3) (cherry picked from commit 039b0b18d3c83c9aa3a80da67f3cf1c2d965a598) --- pkg/repo/index.go | 1 + pkg/repo/index_test.go | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/repo/index.go b/pkg/repo/index.go index e1ce3c62d..a93314ab8 100644 --- a/pkg/repo/index.go +++ b/pkg/repo/index.go @@ -357,6 +357,7 @@ func loadIndex(data []byte, source string) (*IndexFile, error) { for idx := len(cvs) - 1; idx >= 0; idx-- { if cvs[idx] == nil { log.Printf("skipping loading invalid entry for chart %q from %s: empty entry", name, source) + cvs = append(cvs[:idx], cvs[idx+1:]...) continue } // When metadata section missing, initialize with no data diff --git a/pkg/repo/index_test.go b/pkg/repo/index_test.go index a1e3e9438..1fb30f3c0 100644 --- a/pkg/repo/index_test.go +++ b/pkg/repo/index_test.go @@ -68,6 +68,7 @@ entries: grafana: - apiVersion: v2 name: grafana + - null foo: - bar: From 7799b483f52ceb665264a4056da3d2569d60f910 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Thu, 31 Jul 2025 09:25:12 -0400 Subject: [PATCH 2/2] fix Chart.yaml handling Signed-off-by: Matt Farina (cherry picked from commit f13afaacd6f8f9dca4ad914d87fabbe129692eda) --- pkg/chartutil/dependencies.go | 5 +++-- pkg/lint/rules/chartfile.go | 3 +++ pkg/lint/rules/chartfile_test.go | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/chartutil/dependencies.go b/pkg/chartutil/dependencies.go index 36a341927..37452cec7 100644 --- a/pkg/chartutil/dependencies.go +++ b/pkg/chartutil/dependencies.go @@ -16,6 +16,7 @@ limitations under the License. package chartutil import ( + "fmt" "log" "strings" @@ -255,8 +256,8 @@ func processImportValues(c *chart.Chart, merge bool) error { for _, riv := range r.ImportValues { switch iv := riv.(type) { case map[string]interface{}: - child := iv["child"].(string) - parent := iv["parent"].(string) + child := fmt.Sprintf("%v", iv["child"]) + parent := fmt.Sprintf("%v", iv["parent"]) outiv = append(outiv, map[string]string{ "child": child, diff --git a/pkg/lint/rules/chartfile.go b/pkg/lint/rules/chartfile.go index 910602b7d..555ec71ba 100644 --- a/pkg/lint/rules/chartfile.go +++ b/pkg/lint/rules/chartfile.go @@ -151,6 +151,9 @@ func validateChartVersion(cf *chart.Metadata) error { func validateChartMaintainer(cf *chart.Metadata) error { for _, maintainer := range cf.Maintainers { + if maintainer == nil { + return errors.New("a maintainer entry is empty") + } if maintainer.Name == "" { return errors.New("each maintainer requires a name") } else if maintainer.Email != "" && !govalidator.IsEmail(maintainer.Email) { diff --git a/pkg/lint/rules/chartfile_test.go b/pkg/lint/rules/chartfile_test.go index f4c836cf7..4740047be 100644 --- a/pkg/lint/rules/chartfile_test.go +++ b/pkg/lint/rules/chartfile_test.go @@ -143,6 +143,16 @@ func TestValidateChartMaintainer(t *testing.T) { t.Errorf("validateChartMaintainer(%s, %s) to return no error, got %s", test.Name, test.Email, err.Error()) } } + + // Testing for an empty maintainer + badChart.Maintainers = []*chart.Maintainer{nil} + err := validateChartMaintainer(badChart) + if err == nil { + t.Errorf("validateChartMaintainer did not return error for nil maintainer as expected") + } + if err.Error() != "a maintainer entry is empty" { + t.Errorf("validateChartMaintainer returned unexpected error for nil maintainer: %s", err.Error()) + } } func TestValidateChartSources(t *testing.T) {