feat: add optional kindFilter to fromCRD#98
Open
sini wants to merge 1 commit into
Open
Conversation
fromCRD now accepts an optional `kindFilter` (a list of CRD `kind` names). When set, only CustomResourceDefinitions whose kind is in the list are generated; an empty/unset filter (the default) keeps every CRD, so the change is fully backwards compatible. This helps when `crds` points at a multi-document stream — e.g. raw `helm template` output — that contains more kinds than you want to expose. To support that, crd2jsonschema.py also skips null documents (empty or comment-only YAML docs, which yaml.safe_load_all yields as None) instead of raising. Adds unit tests covering kind filtering, the empty-filter passthrough, and null-document skipping.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
kindFilterargument tofromCRD— a list of CRDkindnames. When non-empty, only
CustomResourceDefinitions whosespec.names.kindis in the list are generated. The default[ ]keeps everyCRD found, so this is fully backwards compatible.
This mirrors what
fromChartCRDalready does with itscrdsargument, but forthe
src-basedfromCRDpath.Motivation
fromCRD'scrdsargument is a list of YAML files. When one of those filesis a multi-document stream — e.g. raw
helm template --include-crdsoutput, oran upstream bundle that ships many CRDs in one file — you often want types for
only a subset of the kinds it contains, and no way to narrow that existed on
the
srcpath.kindFilterprovides it.While supporting that,
crd2jsonschema.pyalso learned to skip nulldocuments — empty or comment-only YAML docs, which
yaml.safe_load_allyields as
None. These are common inhelm templateoutput and previouslymade the generator raise; skipping them lets callers feed raw multi-document
streams to
fromCRDdirectly.Example
Compatibility
kindFilterdefaults to[ ]→ no filtering; output identical to today.raise — it changes nothing for valid inputs.
Tests
Adds
test_crd2jsonschema.pycases for kind filtering (hit + empty-filterpassthrough) and null-document skipping —
nix run .#crd2jsonschemaTest.