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 <matt@mattfarina.com>
pull/7543/head
Matt Farina 4 years ago
parent c825a01435
commit ed80cf4548
No known key found for this signature in database
GPG Key ID: 9436E80BFBA46909

@ -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")
}

@ -41,6 +41,10 @@ func TestCRDs(t *testing.T) {
Name: "crdsfoo/bar/baz.yaml",
Data: []byte("hello"),
},
{
Name: "crds/README.md",
Data: []byte("# hello"),
},
},
}

Loading…
Cancel
Save