Skip to content

feat: add optional kindFilter to fromCRD#98

Open
sini wants to merge 1 commit into
arnarg:mainfrom
sini:feat/from-crd-kind-filter
Open

feat: add optional kindFilter to fromCRD#98
sini wants to merge 1 commit into
arnarg:mainfrom
sini:feat/from-crd-kind-filter

Conversation

@sini
Copy link
Copy Markdown
Contributor

@sini sini commented Jun 3, 2026

Summary

Adds an optional kindFilter argument to fromCRD — a list of CRD kind
names. When non-empty, only CustomResourceDefinitions whose
spec.names.kind is in the list are generated. The default [ ] keeps every
CRD found, so this is fully backwards compatible.

This mirrors what fromChartCRD already does with its crds argument, but for
the src-based fromCRD path.

Motivation

fromCRD's crds argument is a list of YAML files. When one of those files
is a multi-document stream — e.g. raw helm template --include-crds output, or
an 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 src path. kindFilter provides it.

While supporting that, crd2jsonschema.py also learned to skip null
documents
— empty or comment-only YAML docs, which yaml.safe_load_all
yields as None. These are common in helm template output and previously
made the generator raise; skipping them lets callers feed raw multi-document
streams to fromCRD directly.

Example

fromCRD {
  name = "cert-manager";
  src = ./crds;                                # a bundle with many CRDs
  crds = [ "crds.yaml" ];
  kindFilter = [ "Certificate" "Issuer" "ClusterIssuer" ];   # generate only these
}

Compatibility

  • kindFilter defaults to [ ] → no filtering; output identical to today.
  • The null-doc skip only avoids a crash on documents that would otherwise
    raise — it changes nothing for valid inputs.

Tests

Adds test_crd2jsonschema.py cases for kind filtering (hit + empty-filter
passthrough) and null-document skipping — nix run .#crd2jsonschemaTest.

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.
@sini sini changed the title feat(generators): add optional kindFilter to fromCRD feat: add optional kindFilter to fromCRD Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant