Skip to content

Conversation

thockin
Copy link
Member

@thockin thockin commented May 10, 2025

This KEP proposes to add a new output format for kubectl, tentatively called “KYAML” (as in kubectl get -o kyaml ...). This format is a strict subset (aka “dialect”) of standard YAML, and so should be parseable by the existing ecosystem. This dialect seeks to emphasize syntactical choices which avoid many of the most common traps in YAML. For example, unlike standard YAML output, this dialect is not whitespace-sensitive, which makes it vastly easier to patch correctly in things like Helm charts.

This KEP further proposes to make KYAML the standard format for all project-owned documentation and examples.

  • One-line PR description: First draft

  • Issue link: KYAML #5295

  • Other comments:

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 10, 2025
@k8s-ci-robot k8s-ci-robot added kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/cli Categorizes an issue or PR as relevant to SIG CLI. labels May 10, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG CLI May 10, 2025
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label May 10, 2025
@thockin
Copy link
Member Author

thockin commented May 10, 2025

/cc @BenTheElder @sftim @liggitt @soltysh

@k8s-ci-robot
Copy link
Contributor

@thockin: GitHub didn't allow me to request PR reviews from the following users: sftim.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @BenTheElder @sftim @liggitt @soltysh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@thockin thockin mentioned this pull request May 10, 2025
15 tasks
@thockin
Copy link
Member Author

thockin commented May 11, 2025

typos fixed and small changes to clarify strings

pohly
pohly previously requested changes May 12, 2025
@github-project-automation github-project-automation bot moved this from Needs Triage to In Progress in SIG CLI May 12, 2025
@thockin thockin force-pushed the kyaml branch 2 times, most recently from fc2ba3c to 0b92cc3 Compare May 12, 2025 19:41
@k8s-ci-robot k8s-ci-robot requested a review from dims May 13, 2025 06:01
@thockin
Copy link
Member Author

thockin commented May 13, 2025

For multi-line strings I added a variation of option 2 with slightly different indenting.

Copy link
Member

@liggitt liggitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't dig into the multi-line strings section, swept the rest

which they copy and modify.
By changing the examples we seed the change in the ecosystem.
One success metric might be
that KYAML becomes the preferred format in the most common helm charts.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how adopting KYAML for Helm chart templates is a tenable idea.

example https://github.com/bitnami/charts/blob/main/bitnami/appsmith/templates/client/deployment.yaml

Getting the Go templating to work correctly is already challenging.
Adding more curly braces to the curly brace soup is not going to be a nice DX.
Cuddling closing YAML curlies makes it worse.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adapted some of that helm chart and it's (IMO) easier to read and gets rid of all the | nindent 8 crap.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is about all it can get rid of while adding a lot more curlies.

But I would guess that if kyaml is used with Go templating people will still want the indentation to make helm template ... output readable, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can run the output of that thru yamlfmt and get either canonical YAML or KYAML.

Yes, the input has strictly more curlies, squares, quotes, and commas, but the result is that you can avoid having to think about the hardest to debug (IMO) problem, the one that has no visible characters involved .

Panacea? No. It's a tradeoff.

Integers and floats are rendered as their natural numeric representation.

Simple strings are rendered as double-quoted and escaped. Multi-line strings
require special consideration, see below.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double-quoting is often problematic in YAML.

Using them for all string values will require backslash escaping of all double-quotes and backslashes, so code snippets will get harder to write, read and understand.

Given the backslash requirements that KYAML adds for multiline scalars, it will get messier.

Imagine a KYAML formatted scalar that itself is a KYAML formatted multiline scalar containing code with double-quotes and backslashes.
The backlashes will become problematic. Especially for newer users for which KYAML was created to protect.

YAML's literal scalar syntax allows you to encode any multiline text string (including other YAML files) by simply indenting.

Allowing single-quoting could help a little here. YAML's single quote only needs escaping for one character; the single quote.
Multilines wouldn't work the same way with single-quotes, as double-quotes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAML's literal scalar syntax allows you to encode any multiline text string (including other YAML files) by simply indenting.

Not once you are inside a flow, though?

go run ./cmd/yamlfmt/
foo: {
  bar: "quoted",
  qux: |
    non-quoted
failed to decode input: yaml: line 3: found character that cannot start any token
exit status 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I was just pointing out that enforcing an all flow style, forgoes literal, which is likely going to be an ongoing pain point for this formatting.

@danwinship
Copy link
Contributor

  • I have a big problem (as an ambassador of YAML) of encouraging YAML's largest user ecosystem to write YAML in a style that eschews parts of YAML that make so many people like it

It's not a coincidence that this is coming out of YAML's largest user ecosystem. As Tim said, "The things that make YAML great at small scale become a liability at large scale."

If that is the goal, isn't JSON by far the most reliable format?

If JSON had comments and trailing commas, probably.

there are a lot of YAML cases that haven't been addressed here yet

Because KYAML only needs to concern itself with the cases that are used for representing k8s objects. For example.:

Imagine a KYAML formatted scalar that itself is a KYAML formatted multiline scalar containing code with double-quotes and backslashes.

No k8s API objects contain stringified YAML.

@thockin
Copy link
Member Author

thockin commented Jun 1, 2025

No k8s API objects contain stringified YAML.

To be fair, people DO embed YAML and JSON into annotations or configmaps. The uglitude of additional escaping is not lost on me

@lmktfy
Copy link

lmktfy commented Jun 2, 2025

Embedded YAML (and JSON) show up in some extension APIs too. Such is life.

@thockin
Copy link
Member Author

thockin commented Jun 2, 2025

Is anything pending on this to prevent merge?

@thockin
Copy link
Member Author

thockin commented Jun 5, 2025

Dear reviewers - have I missed anything to get this merged?

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve
from sig-cli pov
/hold
so @jpbetz can have final PRR saying on this PR and it doesn't merge w/o his approval

In addition to `kubectl` output,
most Kubernetes config files are either YAML or JSON.
JSON lacks comments,
which are very valuable for configuration,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KYAML style formatting certainly doesn't make YAML nicer to read by people. Just less problematic to read by code.
If that is the goal, isn't JSON by far the most reliable format?

I'm seeing KYAML as a sweet spot between JSON's reliability and YAML's readability. Obviously it has it's pros and cons, as every other format, but for k8s use cases I trust the pros outweigh the cons in this case.

To make this change, we will:
1. Create new code (see details below) which serializes any object into KYAML.
2. Introduce a kubectl output format, `-o=kyaml`, which uses this new package.
3. Create tooling which reformats YAML or JSON as KYAML (see details below).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be best IF we want to move it to k-sigs to move it to it's own repo as a thin CLI wrapper around sigs.k8s.io/yaml, but then we have to manage releasing etc seperately.

That's a reasonable middle-ground. But before doing so we can investigate which parts in Tim's branch we could modify such that it could live as part of sigs.k8s.io/yaml. I'm pretty sure that the KYAMLEncoder should be part of that yaml library of ours, which only leaves the diff library at question. But resolving this is definitely not something we need to deal with here.

4. Work with SIG Docs to update examples to this format, both example command-lines and examples of API objects.
5. Look for other examples across kubernetes-affiliated git repositories, and offer PRs to convert to KYAML.
6. Make a lot of noise about it, and try to get more people to use it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an explicit non-goal which states: 3. Require projects to migrate to KYAML by default. and that's a reasonable approach.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 5, 2025
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 5, 2025
@jpbetz
Copy link
Contributor

jpbetz commented Jun 5, 2025

/approve
For PRR

As far as I can tell, KYAML don't have any production impacting implications given that it is an opt-in strict subset of YAML.

@jpbetz
Copy link
Contributor

jpbetz commented Jun 5, 2025

/hold
For non-PRR approval

Copy link

@ingydotnet ingydotnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting Helm team member opinions for this KEP.

Perhaps worst of all,
template-expanding systems,
such as the widely used `helm`,
force users to get whitespace "just right"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helm charts done with kyaml would be much less readable/maintainable with all the curlies already required by Go templating.

Also while indentation isn't a parsing issue in kyaml, it certainly is an issue wrt readability.
It's disingenuous to say that the nindents will go away.
They won't since the output of helm template ... needs to be human readable/parsable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helm template | yamlfmt (or yq) works

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue the development of Helm templates will be more difficult. Most users of Helm never look at the generated output. They just see what's installed.

My concern would be that YAML structures and practices for k8s (helm included) are already widely set. Making changes to that is going to cause confusion.

The developer experience for Helm templates, and k8s yaml based things in general, will go down by using a style that's not widely used or documented in the world at large.

many of the most common traps in YAML.
For example, unlike standard YAML output,
this dialect is not whitespace-sensitive,
which makes it vastly easier to patch correctly in things like Helm charts.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I brought up this KEP in the Helm Weekly Developer Meeting which I regularly participate.
I'd like to get Helm release manage @mattfarina 's take on all of it noted here.

My take is that while you are saying this is optional, you really are suggesting that people use/recommend/document an entirely new format, that while technically valid YAML, will not be recognized by most users as such.
YAML has been in k8s since the start. That's 10+ years of establishment that is trying to be changed.
And for what I see is: trading a couple common issues for a whole new set of them.

cc: @banjoh @scottrigby @gjenkins8 from https://github.com/helm/helm

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine to take feedback, but I don't think we should block merge on that. The KEP window closes soon, and I am travelling in a week, so I don't want to miss it on technicality.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When does the KEP window close?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just under a week.

@ingydotnet
Copy link

Dear reviewers - have I missed anything to get this merged?

I'd like to wait and see what some of the Helm maintainers I referenced in my recent review have to offer here, before it gets merged.

They are very well seasoned in k8s and its ecosystem.

@lmktfy
Copy link

lmktfy commented Jun 5, 2025 via email

@thockin
Copy link
Member Author

thockin commented Jun 5, 2025

+1 @lmktfy

This KEP proposes to add a new output format for kubectl, tentatively
called “KYAML” (as in `kubectl get -o kyaml ...`). This format is a
strict subset (aka “dialect”) of standard YAML, and so should be
parseable by the existing ecosystem. This dialect seeks to emphasize
syntactical choices which avoid many of the most common traps in YAML.
For example, unlike standard YAML output, this dialect is not
whitespace-sensitive, which makes it vastly easier to patch correctly in
things like Helm charts.

This KEP further proposes to make KYAML the standard format for all
project-owned documentation and examples.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 5, 2025
@thockin
Copy link
Member Author

thockin commented Jun 5, 2025

I made a super small change to back-tick some punctuation in the text.

Approvers are @liggitt and @soltysh

@thockin
Copy link
Member Author

thockin commented Jun 5, 2025

@kubernetes/sig-docs-leads may want to look, too, since this proposes to edit docs.

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/hold cancel
I don't see a reason why we should wait further with merging this document. Doing so does not mean we're not open to feedback, which can be addressed at any later point in time, either during implementation or during later stages (beta, ga) as this enhancement progresses.

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Jun 6, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jpbetz, soltysh, thockin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 05ee553 into kubernetes:master Jun 6, 2025
4 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.34 milestone Jun 6, 2025
@github-project-automation github-project-automation bot moved this from In Progress to Done in SIG CLI Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.