Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Ensure schemapatcher does not error when non CRD yaml files are present #724

Merged
merged 1 commit into from Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/schemapatcher/gen.go
Expand Up @@ -358,12 +358,16 @@ func crdsFromDirectory(ctx *genall.GenerationContext, dir string) (map[schema.Gr
if err := kyaml.Unmarshal(rawContent, &typeMeta); err != nil {
continue
}

if typeMeta.APIVersion == "" || typeMeta.Kind != "CustomResourceDefinition" {
// If there's no API version this file probably isn't a CRD.
// Likewise we don't need to care if the Kind isn't CustomResourceDefinition.
continue
}

if !isSupportedAPIExtGroupVer(typeMeta.APIVersion) {
return nil, fmt.Errorf("load %q: apiVersion %q not supported", filepath.Join(dir, fileInfo.Name()), typeMeta.APIVersion)
}
if typeMeta.Kind != "CustomResourceDefinition" {
continue
}

// collect the group-kind and versions from the actual structured form
var actualCRD crdIsh
Expand Down
3 changes: 3 additions & 0 deletions pkg/schemapatcher/testdata/valid/example.cr.yaml
@@ -0,0 +1,3 @@
# This is an example of the resource defined in this package.
apiVersion: kubebuilder.schemapatcher.controller-tools.sigs.k8s.io/v1
kind: Example
1 change: 1 addition & 0 deletions pkg/schemapatcher/testdata/valid/random.yaml
@@ -0,0 +1 @@
name: This is a random YAML file to ensure the generator doesn't error with non-kube YAML files.