Skip to content

loewenthal-corp/kyaml

Repository files navigation

kyaml

KYAML formatter and validator — converts YAML to Kubernetes YAML (KYAML), a safer and less ambiguous subset of YAML introduced in Kubernetes v1.34 (KEP-5295).

What is KYAML?

KYAML is a strict subset of YAML designed specifically for Kubernetes. Any KYAML document is valid YAML, but KYAML eliminates common pitfalls:

  • Double-quoted strings — no more implicit type coercion (NOfalse)
  • Flow-style syntax — uses {} for maps and [] for lists, making it whitespace-insensitive
  • Comments — unlike JSON, KYAML supports comments
  • Trailing commas — allowed for cleaner diffs

Install

go install github.com/loewenthal-corp/kyaml/cmd/kyaml@latest

Or download a binary from the releases page.

Usage

Format

Convert YAML files to KYAML:

# Format a file (print to stdout)
kyaml format deployment.yaml

# Format and write back
kyaml format -w deployment.yaml

# Format all YAML files in a directory
kyaml format -w ./manifests/

# Format from stdin
cat service.yaml | kyaml format

The fmt alias also works:

kyaml fmt -w .

Validate

Check if files are already valid KYAML:

# Validate a file
kyaml validate deployment.yaml

# Validate all YAML files in a directory
kyaml validate ./manifests/

Exit code is 1 if any file is not valid KYAML.

Example

Input (service.yaml):

apiVersion: v1
kind: Service
metadata:
  name: my-service
  labels:
    app: web
spec:
  type: ClusterIP
  ports:
    - port: 80
      protocol: TCP
      targetPort: 8080
  selector:
    app: web

Output (kyaml format service.yaml):

---
{
  apiVersion: "v1",
  kind: "Service",
  metadata: {
    name: "my-service",
    labels: {
      app: "web",
    },
  },
  spec: {
    type: "ClusterIP",
    ports: [{
      port: 80,
      protocol: "TCP",
      targetPort: 8080,
    }],
    selector: {
      app: "web",
    },
  },
}

Development

task do        # Run all quality checks
task test      # Run tests
task build     # Build binary
task install   # Install to ~/go/bin

About

KYAML formatter and validator

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages