Add Kubernetes type annotations#5
Merged
Merged
Conversation
…closure Embeds the pinned v1.32.1 Kubernetes JSON Schema (definitions.json) via go:embed and exposes Definitions(). Resolve maps a short GVK like core/v1/ResourceRequirements to its fully-qualified definition key. Closure returns a key plus every transitively-referenced definition, cycle-safe for self-referential types.
A k8s-typed node emits $ref into the embedded definitions; arrays wrap the ref in items, nullable fields use anyOf with null, and nullable array items wrap items in anyOf. Generate collects every K8sRef in the tree and attaches the merged transitive closure as top-level definitions. K8s fields are never marked required (their shape is validated by the embedded schema). No description is attached to a $ref (draft-07 ignores siblings).
A k8s-typed field shows as a single row whose type cell displays the GVK (the k8s: prefix stripped, with a ? suffix when nullable). flatten treats a k8s node as a leaf even when it carries inferred children from a concrete value, so the inferred structure is not descended into.
Parses a fixture with a ResourceRequirements field and a nullable PodSecurityContext, generates the schema, compiles it as draft-07, and asserts a valid Kubernetes document passes while a malformed one fails.
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.
Annotate a values.yaml field with a Kubernetes type; helm-scribe resolves it against an embedded, pinned schema and emits it into both
values.schema.json(via$ref) and the README table.Usage
Syntax:
k8s:<group>/<version>/<Kind>, with the usual[](array) and?(nullable) suffixes. Group suffixes likenetworking.k8s.ionormalize tonetworking.Behavior
$refinto a top-leveldefinitionsblock containing only the transitive closure of used types. Nullability usesanyOfwith{"type":"null"}(never a siblingtypeof$ref). K8s fields are neverrequired.?when nullable).@enum/@min/@max/@pattern/@itemon a k8s field are ignored with a warning.Pinned to Kubernetes v1.32.1 (
KubeSchemaVersioninkube/kube.go); refreshingkube/definitions.jsonis manual for now.Testing
Unit tests across
kube/parser/schema/readme, plus an e2e test that compiles the generated schema as draft-07 and validates real Kubernetes documents.go test ./...andgo vet ./...clean.Attribution
Embedded schema from yannh/kubernetes-json-schema (Apache-2.0).