Skip to content

Add Kubernetes type annotations#5

Merged
Miosp merged 5 commits into
masterfrom
kubernetes-types
Jun 30, 2026
Merged

Add Kubernetes type annotations#5
Miosp merged 5 commits into
masterfrom
kubernetes-types

Conversation

@Miosp

@Miosp Miosp commented Jun 30, 2026

Copy link
Copy Markdown
Owner

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

# @type k8s:core/v1/ResourceRequirements
resources: {}

# @type k8s:core/v1/Container[]
containers: []

# @type k8s:core/v1/PodSecurityContext?
securityContext:

Syntax: k8s:<group>/<version>/<Kind>, with the usual [] (array) and ? (nullable) suffixes. Group suffixes like networking.k8s.io normalize to networking.

Behavior

  • Schema: $ref into a top-level definitions block containing only the transitive closure of used types. Nullability uses anyOf with {"type":"null"} (never a sibling type of $ref). K8s fields are never required.
  • README: one compact row showing the GVK (? when nullable).
  • Parser: unknown GVK warns and falls back to a permissive object; @enum/@min/@max/@pattern/@item on a k8s field are ignored with a warning.

Pinned to Kubernetes v1.32.1 (KubeSchemaVersion in kube/kube.go); refreshing kube/definitions.json is 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 ./... and go vet ./... clean.

Attribution

Embedded schema from yannh/kubernetes-json-schema (Apache-2.0).

Miosp added 5 commits June 30, 2026 21:16
…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.
Adds K8sRef to ValueNode. The parser resolves k8s:-prefixed @type values
via kube.Resolve, stores the definition key, and on failure falls back to
a permissive object with a warning. Conflicting constraints
(@enum/@min/@max/@pattern/@item) on a k8s field are cleared with a warning.
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.
@Miosp Miosp self-assigned this Jun 30, 2026
@Miosp
Miosp merged commit 62ffa53 into master Jun 30, 2026
6 checks passed
@Miosp
Miosp deleted the kubernetes-types branch June 30, 2026 19:27
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