Skip to content

Commit

Permalink
Merge pull request #724 from JoelSpeed/ignore-non-crd-yaml
Browse files Browse the repository at this point in the history
馃悰 Ensure schemapatcher does not error when non CRD yaml files are present
  • Loading branch information
k8s-ci-robot committed Sep 16, 2022
2 parents f69ced4 + 9928e69 commit 24d788a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
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.

0 comments on commit 24d788a

Please sign in to comment.