Importing Existing YAML
Chant can parse existing Kubernetes YAML manifests and generate typed TypeScript source files. This is useful for migrating existing infrastructure to chant.
How it works
Section titled “How it works”Input YAML → parse → generate TypeScript → export typed resourcesThe importer reads multi-document YAML, identifies each resource’s apiVersion and kind, and generates the corresponding typed constructor call. The output is a valid .k8s.ts file you can immediately build with chant build.
Running the import roundtrip
Section titled “Running the import roundtrip”From the lexicons/k8s directory:
# Full roundtrip — clones kubernetes/examples, imports, serializes, comparesjust full-roundtrip
# Skip clone if repo is already cachedjust full-roundtrip --skip-clone
# Verbose output + filter to a specific manifestjust full-roundtrip --skip-clone --verbose --manifest guestbook
# Skip the serialize phase (parse + generate only)just full-roundtrip --skip-clone --skip-serializeParse-only mode
Section titled “Parse-only mode”For quick validation without the full serialize cycle:
just import-samples --skip-clone --verbose
# Filter to a specific manifestjust import-samples --skip-clone --verbose --manifest guestbookThis runs the YAML → TypeScript generation but skips the round-trip comparison.
What “pass” means
Section titled “What “pass” means”A passing roundtrip means the serialized YAML, when re-parsed, produces the same number of resources with matching kind values. Exact YAML comparison is intentionally skipped — key ordering, quoting, and comments differ between input and output.
Validating against a cluster
Section titled “Validating against a cluster”To verify the serialized output is valid Kubernetes YAML, apply it to a local k3d cluster:
# Create a k3d cluster, apply serialized manifests, verify, tear downjust k3d-validate
# Keep the cluster for manual inspectionjust k3d-validate --keep-cluster
# Reuse an existing clusterjust k3d-validate --reuse-cluster --verboseSee Testing & Validation for full details on the k3d validation workflow.
Limitations
Section titled “Limitations”The import pipeline does not support:
- Helm charts — template syntax (
{{ .Values.x }}) is not valid YAML - Kustomize overlays — overlays are processed by kustomize before producing YAML
- Custom Resource Definitions (CRDs) — only built-in K8s resource types are recognized
- Cloud-specific volumes — provider-specific volume types (awsElasticBlockStore, gcePersistentDisk) are parsed but excluded from k3d cluster validation (k3d doesn’t provide cloud volume drivers)