From ed80cf4548712cb779bd1607f98dff21d905d346 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Thu, 6 Feb 2020 12:26:23 -0500 Subject: [PATCH] Fixes issue where non-CRDs are read in from the crd directory For example, a readme markdown is read in and parsed Closes #7536 Signed-off-by: Matt Farina --- pkg/chart/chart.go | 9 +++++++-- pkg/chart/chart_test.go | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 1a85373b9..bd75375a4 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -135,7 +135,7 @@ func (ch *Chart) CRDs() []*File { files := []*File{} // Find all resources in the crds/ directory for _, f := range ch.Files { - if strings.HasPrefix(f.Name, "crds/") { + if strings.HasPrefix(f.Name, "crds/") && hasManifestExtension(f.Name) { files = append(files, f) } } @@ -151,7 +151,7 @@ func (ch *Chart) CRDObjects() []CRD { crds := []CRD{} // Find all resources in the crds/ directory for _, f := range ch.Files { - if strings.HasPrefix(f.Name, "crds/") { + if strings.HasPrefix(f.Name, "crds/") && hasManifestExtension(f.Name) { mycrd := CRD{Name: f.Name, Filename: filepath.Join(ch.ChartFullPath(), f.Name), File: f} crds = append(crds, mycrd) } @@ -162,3 +162,8 @@ func (ch *Chart) CRDObjects() []CRD { } return crds } + +func hasManifestExtension(fname string) bool { + ext := filepath.Ext(fname) + return strings.EqualFold(ext, ".yaml") || strings.EqualFold(ext, ".yml") || strings.EqualFold(ext, ".json") +} diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index 724e52933..ef623fff6 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -41,6 +41,10 @@ func TestCRDs(t *testing.T) { Name: "crdsfoo/bar/baz.yaml", Data: []byte("hello"), }, + { + Name: "crds/README.md", + Data: []byte("# hello"), + }, }, }