From 02042ef887df68ca73406f591eb149d36c56e424 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Mon, 14 Jul 2025 09:24:18 -0700 Subject: [PATCH] Add KYAML support to kubectl KYAML is a strict subset of YAML, which is sort of halfway between YAML and JSON. It has the following properties: * Does not depend on whitespace (easier to text-patch and template). * Always quotes value strings (no ambiguity aroud things like "no"). * Allows quoted keys, but does not require them, and only quotes them if they are not obviously safe (e.g. "no" would always be quoted). * Always uses {} for structs and maps (no more obscure errors about mapping values). * Always uses [] for lists (no more trying to figure out if a dash changes the meaning). * When printing, it includes a header which makes it clear this is YAML and not ill-formed JSON. * Allows trailing commas * Allows comments, * Tries to economize on vertical space by "cuddling" some kinds of brackets together. * Retains comments. Examples: A struct: ```yaml metadata: { creationTimestamp: "2024-12-11T00:10:11Z", labels: { app: "hostnames", }, name: "hostnames", namespace: "default", resourceVersion: "15231643", uid: "f64dbcba-9c58-40b0-bbe7-70495efb5202", } ``` A list of primitves: ```yaml ipFamilies: [ "IPv4", "IPv6", ] ``` A list of structs: ```yaml ports: [{ port: 80, protocol: "TCP", targetPort: 80, }, { port: 443, protocol: "TCP", targetPort: 443, }] ``` A multi-document stream: ```yaml --- { foo: "bar", } --- { qux: "zrb", } ``` Kubernetes-commit: 2cb955d8ccae30167b9610bfe51c2f86e83a1958 --- pkg/cmd/util/helpers.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/cmd/util/helpers.go b/pkg/cmd/util/helpers.go index 2857d5a14..282682044 100644 --- a/pkg/cmd/util/helpers.go +++ b/pkg/cmd/util/helpers.go @@ -455,6 +455,12 @@ const ( // Transition to WebSockets. RemoteCommandWebsockets FeatureGate = "KUBECTL_REMOTE_COMMAND_WEBSOCKETS" PortForwardWebsockets FeatureGate = "KUBECTL_PORT_FORWARD_WEBSOCKETS" + + // owner: @thockin + // kep: https://kep.k8s.io/5296 + // + // Support KYAML output. + KYAMLOutput FeatureGate = "KUBECTL_KYAML" ) // IsEnabled returns true iff environment variable is set to true.