From 1c48dc4aac4206c8f51bd77b327defb7a37cbe13 Mon Sep 17 00:00:00 2001 From: Arnob kumar saha Date: Fri, 21 Aug 2026 19:27:07 +0600 Subject: [PATCH] Skip non-YAML files in check-schema Every hub package embeds a 'trigger' sentinel file (content: 'load') for the hot-reload path. sc.CheckFS walks every file in the embedded FS with no extension filter, so it tried to unmarshal that string as an object and check-schema panicked before checking any real YAML. Filter to *.yaml locally instead of bumping kmodules.xyz/schema-checker. Signed-off-by: Arnob kumar saha --- cmd/check-schema/main.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/cmd/check-schema/main.go b/cmd/check-schema/main.go index 9a3d9e4372..4c6eb0a484 100644 --- a/cmd/check-schema/main.go +++ b/cmd/check-schema/main.go @@ -17,6 +17,10 @@ limitations under the License. package main import ( + "fmt" + "io/fs" + "path/filepath" + "kmodules.xyz/resource-metadata/apis/meta/v1alpha1" uiapi "kmodules.xyz/resource-metadata/apis/ui/v1alpha1" blockdefs "kmodules.xyz/resource-metadata/hub/resourceblockdefinitions" @@ -28,19 +32,37 @@ import ( ) func main() { - if err := sc.CheckFS(blockdefs.EmbeddedFS(), &v1alpha1.ResourceBlockDefinition{}); err != nil { + if err := checkYAMLs(blockdefs.EmbeddedFS(), &v1alpha1.ResourceBlockDefinition{}); err != nil { panic(err) } - if err := sc.CheckFS(resourcedescriptors.EmbeddedFS(), &v1alpha1.ResourceDescriptor{}); err != nil { + if err := checkYAMLs(resourcedescriptors.EmbeddedFS(), &v1alpha1.ResourceDescriptor{}); err != nil { panic(err) } - if err := sc.CheckFS(resourceoutlines.EmbeddedFS(), &v1alpha1.ResourceOutline{}); err != nil { + if err := checkYAMLs(resourceoutlines.EmbeddedFS(), &v1alpha1.ResourceOutline{}); err != nil { panic(err) } - if err := sc.CheckFS(tabledefs.EmbeddedFS(), &v1alpha1.ResourceTableDefinition{}); err != nil { + if err := checkYAMLs(tabledefs.EmbeddedFS(), &v1alpha1.ResourceTableDefinition{}); err != nil { panic(err) } - if err := sc.CheckFS(dashboards.EmbeddedFS(), &uiapi.ResourceDashboard{}); err != nil { + if err := checkYAMLs(dashboards.EmbeddedFS(), &uiapi.ResourceDashboard{}); err != nil { panic(err) } } + +// hub packages embed a non-YAML "trigger" sentinel file for hot reload, +// which sc.CheckFS would try to parse as an object. +func checkYAMLs(fsys fs.FS, v interface{}) error { + return fs.WalkDir(fsys, ".", func(path string, e fs.DirEntry, err error) error { + if err != nil || e.IsDir() || filepath.Ext(path) != ".yaml" { + return err + } + d, err := sc.New(fsys).CheckObject(v, path) + if err != nil { + return err + } + if d != "" { + return fmt.Errorf("%s: object does not match schema, diff: %s", path, d) + } + return nil + }) +}