13
0
Fork 0
mirror of https://github.com/yannh/kubeconform.git synced 2026-07-04 10:29:30 +00:00

fix: avoid panic when a schema document decodes to null

This commit is contained in:
somaz 2026-06-04 16:34:50 +09:00
parent d412494432
commit c6a177dc87
2 changed files with 41 additions and 0 deletions

View file

@ -372,6 +372,13 @@ func downloadSchema(registries []registry.Registry, l jsonschema.SchemeURLLoader
for _, reg := range registries {
path, s, err = reg.DownloadSchema(kind, version, k8sVersion)
if err == nil {
// A schema document that decodes to nil (for example a file whose
// entire content is the literal "null") is accepted by AddResource
// but makes Compile dereference a nil root and panic. Treat it as a
// non-parseable response and try the next registry instead.
if s == nil {
continue
}
c := jsonschema.NewCompiler()
c.RegisterFormat(&jsonschema.Format{"duration", validateDuration})
c.UseLoader(l)