Skip to content

Add opt-in serialization variants to code_sample - #58042

Open
TineoC wants to merge 1 commit into
kubernetes:mainfrom
TineoC:kyaml/dual-render-silent
Open

TineoC wants to merge 1 commit into
kubernetes:mainfrom
TineoC:kyaml/dual-render-silent

Conversation

@TineoC

@TineoC TineoC commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Lets code_sample show a sample in more than one format, as tabs. Opt-in per sample:

{{% code_sample file="pods/simple-pod.yaml" variants="kyaml" %}}

The extra file is read from content/<lang>/examples-kyaml/. Without variants, nothing changes. No page uses it yet.

Split from the original version of this PR, per review:

  1. Show a sample in several formats (this PR)
  2. Generate the KYAML files: Add tooling to generate KYAML example variants #59129
  3. Use KYAML on pages: follow-up

Test: Hugo shortcodes (new section), Pods (renders as before).

Issue

Part of #57030 (KEP-5295). Relates to #59129.

This PR was written in part with the assistance of generative AI.

/sig docs
/language en

@kubernetes-prow kubernetes-prow Bot added this to the 1.38 milestone Oct 13, 2026
@kubernetes-prow kubernetes-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. sig/docs Categorizes an issue or PR as relevant to SIG Docs. language/en Issues or PRs related to English language cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 13, 2026
@kubernetes-prow kubernetes-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 13, 2026
@netlify

netlify Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

✅ Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit a792b06
🔍 Latest deploy log https://app.netlify.com/projects/kubernetes-io-main-staging/deploys/6af27d0037bd93dff659f780
😎 Deploy Preview https://deploy-preview-58042--kubernetes-io-main-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@TineoC

TineoC commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author
image

@TineoC

TineoC commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

From 10-13-2026 SIG Docs meeting:

  • This feature don't have to be part of a particular milestone because KYAML is already on main.

Notes to @TineoC: This pr should target main instead of dev-1.38

cc. @lmktfy @katcosgrove

@TineoC
TineoC force-pushed the kyaml/dual-render-silent branch from e8022db to ca3c1f6 Compare October 15, 2026 14:39
@kubernetes-prow kubernetes-prow Bot added area/blog Issues or PRs related to the Kubernetes Blog subproject area/localization General issues or PRs related to localization language/de Issues or PRs related to German language language/fa Issues or PRs related to Persian language language/fr Issues or PRs related to French language language/ko Issues or PRs related to Korean language language/pl Issues or PRs related to Polish language and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 15, 2026
@TineoC
TineoC changed the base branch from dev-1.38 to main October 15, 2026 14:39
@kubernetes-prow kubernetes-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. language/pt Issues or PRs related to Portuguese language labels Oct 15, 2026
@TineoC
TineoC marked this pull request as ready for review October 15, 2026 14:39
@kubernetes-prow kubernetes-prow Bot added language/ru Issues or PRs related to Russian language language/uk Issues or PRs related to Ukrainian language language/zh Issues or PRs related to Chinese language and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 15, 2026
@kubernetes-prow kubernetes-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 15, 2026
@TineoC

TineoC commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

/remove-area blog
/remove-area localization
/remove-language ko
/remove-language zh
/remove-language fr
/remove-language de
/remove-language pt
/remove-language ru
/remove-language pl
/remove-language uk
/remove-language fa

@kubernetes-prow kubernetes-prow Bot removed area/blog Issues or PRs related to the Kubernetes Blog subproject area/localization General issues or PRs related to localization language/ko Issues or PRs related to Korean language language/zh Issues or PRs related to Chinese language language/fr Issues or PRs related to French language language/de Issues or PRs related to German language language/pt Issues or PRs related to Portuguese language language/ru Issues or PRs related to Russian language language/pl Issues or PRs related to Polish language language/uk Issues or PRs related to Ukrainian language language/fa Issues or PRs related to Persian language labels Oct 15, 2026

@lmktfy lmktfy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this. Sorry it's been a while waiting on reviews.

Overall, I think we can split this more.

  1. changes to make it possible to have multiple serializations of the same code (or manifest) sample
  2. changes to make it easier to work with KYAML

  1. actually using KYAML in some pages
    (and personally, I like the idea that we verify it works, then split off the commit for this into its own separate / follow-up PR)

Comment on lines +159 to +160
`scripts/README.md` covers the rest: why the conventional YAML stays canonical,
which manifests get no KYAML rendering, and how localizations opt in.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This reads like AI. Consider rewording it?

Comment on lines +2 to +15
Returns the objects a manifest describes, as JSON, one entry per document in it.
Comparing that instead of the text is how two renderings of one manifest are
checked against each other: a dialect changes the spelling, so only the decoded
objects are comparable.

Expects a dict with:
key a name unique to this manifest and dialect, for the temporary
resource; derive it from the path actually read, so that two
languages holding the same manifest name do not share one resource
content the manifest text

Each document goes through a .yaml-named resource because transform.Unmarshal
guesses a bare string's format and KYAML's leading brace reads as JSON; jsonify
then orders the keys, leaving only meaning to compare.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the purpose of this partial? I don't quite get it.

Comment thread layouts/partials/code-sample-pane.html Outdated
@@ -0,0 +1,24 @@
{{- /*
Renders one example manifest.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Renders one example manifest.
Renders one example code sample (usually a manifest).

Comment thread layouts/partials/tabs.html Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Docsy provides a similar shortcode; are we drifting further from it?

Comment thread layouts/shortcodes/code_sample.html Outdated
Comment on lines +26 to +29
{{/* The dialects an example can be offered in besides the conventional YAML it
is written as, from params.codeSampleDialects in hugo.toml. Configuring one
and generating for it are separate: nothing here changes a page until a
generator has left renderings in content/<lang>/examples-<name>. */}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't imply or assume that a code sample defaults to YAML.

Comment thread layouts/shortcodes/code_sample.html Outdated
Comment on lines +60 to +64
{{/* The tabs are the site's own, from layouts/partials/tabs.html, so a dialect
chosen here is remembered the way every other tab choice on the site is:
the persistence key is the dialect's name, so picking one picks it for every
other example and the choice survives to the next page. Without JavaScript
the first tab, conventional YAML, is the one shown. */}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't imply or assume that a code sample defaults to YAML.

Also, we should try to align more with Docsy where we can.

Comment thread layouts/shortcodes/code_sample.html Outdated
the persistence key is the dialect's name, so picking one picks it for every
other example and the choice survives to the next page. Without JavaScript
the first tab, conventional YAML, is the one shown. */}}
{{ $tabs := slice (dict "label" "YAML" "persist" "yaml" "content" (partial "code-sample-pane.html" $yamlPane)) }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't imply or assume that a code sample defaults to YAML. However, it's OK to have a special kind of code_sample that does have a list of variant serializations. Or other approaches, so long as we aren't disallowing plain-JSON code samples, etc.

Comment thread layouts/shortcodes/code_sample.html Outdated
"tabindex" "0"
"tabs" $tabs) }}
{{ else }}
{{ partial "code-sample-pane.html" $yamlPane }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't imply or assume that a code sample defaults to YAML.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Docsy provides a similar shortcode; are we drifting further from it?

Comment thread scripts/README.md Outdated

This script renders selected example manifests a second time as
[KYAML](https://kubernetes.io/docs/reference/encodings/kyaml/), so the
`code_sample` shortcode can show them in either dialect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't imply or assume that a code sample defaults to YAML. A minor rewording is all that's needed here.

Comment thread scripts/kyaml_examples.txt Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this should be placed in scripts.

Signed-off-by: Christopher Tineo <christophertineo02@gmail.com>
@TineoC
TineoC force-pushed the kyaml/dual-render-silent branch from ca3c1f6 to a792b06 Compare November 10, 2026 02:10
@kubernetes-prow kubernetes-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 10, 2026
@TineoC TineoC changed the title Serve example manifests in KYAML and YAML Add opt-in serialization variants to code_sample Nov 10, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign dipesh-rawat for approval. For more information see the Code Review Process.

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

Details 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

@TineoC

TineoC commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@TineoC

TineoC commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

the solution is kyaml-specific (specially if you see #59129). Do you think might be worth making this extensible for future variants?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. language/en Issues or PRs related to English language sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants